From f0039f4d5a89c5936a312e6818e1151ea95e1a2f Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Wed, 8 Apr 2026 20:48:24 +0800 Subject: [PATCH] fix: add timeout, HEAD method, and meaningful errors to registryValidation - Add 5-second AbortController timeout to prevent indefinite hangs - Use HEAD instead of GET for lighter-weight validation - Include original error message in thrown error for better debugging - Handle AbortError specifically with clear timeout message Fixes asyncapi/cli#2027 --- src/utils/generate/registry.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/utils/generate/registry.ts b/src/utils/generate/registry.ts index 16fdda2e5..f165663e7 100644 --- a/src/utils/generate/registry.ts +++ b/src/utils/generate/registry.ts @@ -8,12 +8,22 @@ export function registryURLParser(input?: string) { export async function registryValidation(registryUrl?: string, registryAuth?: string, registryToken?: string) { if (!registryUrl) { return; } + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 5000); try { - const response = await fetch(registryUrl as string); + const response = await fetch(registryUrl as string, { + method: 'HEAD', + signal: controller.signal, + }); + clearTimeout(timeoutId); if (response.status === 401 && !registryAuth && !registryToken) { throw new Error('You Need to pass either registryAuth in username:password encoded in Base64 or need to pass registryToken'); } - } catch { - throw new Error(`Can't fetch registryURL: ${registryUrl}`); + } catch (error) { + clearTimeout(timeoutId); + if (error instanceof Error && error.name === 'AbortError') { + throw new Error(`Registry URL unreachable (timeout after 5s): ${registryUrl}`); + } + throw new Error(`Can't fetch registryURL: ${registryUrl} — ${error instanceof Error ? error.message : String(error)}`); } }