Skip to content

Commit 86c186a

Browse files
Pyinerclaude
andcommitted
fix: prevent CLI hang when --registry-url points to unreachable host (#2027)
Add AbortController with 5-second timeout to the fetch call in registryValidation() so the CLI no longer hangs indefinitely. Switch from GET to HEAD for a lighter validation request, and surface distinct error messages for timeout vs general network failures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2e6967c commit 86c186a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/utils/generate/registry.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@ export function registryURLParser(input?: string) {
88

99
export async function registryValidation(registryUrl?: string, registryAuth?: string, registryToken?: string) {
1010
if (!registryUrl) { return; }
11+
const TIMEOUT_MS = 5000;
12+
const controller = new AbortController();
13+
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
1114
try {
12-
const response = await fetch(registryUrl as string);
15+
const response = await fetch(registryUrl as string, {
16+
method: 'HEAD',
17+
signal: controller.signal,
18+
});
1319
if (response.status === 401 && !registryAuth && !registryToken) {
1420
throw new Error('You Need to pass either registryAuth in username:password encoded in Base64 or need to pass registryToken');
1521
}
16-
} catch {
17-
throw new Error(`Can't fetch registryURL: ${registryUrl}`);
22+
} catch (error: unknown) {
23+
if (error instanceof Error && error.name === 'AbortError') {
24+
throw new Error(`Registry URL validation timed out after ${TIMEOUT_MS / 1000}s — the host at ${registryUrl} appears unreachable.`);
25+
}
26+
if (error instanceof Error && error.message.startsWith('You Need to pass')) {
27+
throw error;
28+
}
29+
throw new Error(`Unable to reach registry at ${registryUrl}. Ensure the URL is correct and the host is reachable.`);
30+
} finally {
31+
clearTimeout(timeoutId);
1832
}
1933
}

0 commit comments

Comments
 (0)