Skip to content

Commit 5ce2eb8

Browse files
committed
fix(engine): narrow network error shapes honestly
1 parent c01f6b4 commit 5ce2eb8

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎packages/engine/src/utils/urlDownloader.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ function classifyDownloadFailure(error: unknown): UrlDownloadError {
7373
if (isRetryableNetworkCause(current)) {
7474
return new UrlDownloadError("network", true, `Download failed: ${message}`);
7575
}
76-
current = (current as Error & { cause?: unknown }).cause;
76+
current =
77+
typeof current === "object" && current !== null && "cause" in current
78+
? current.cause
79+
: undefined;
7780
}
7881
return new UrlDownloadError("filesystem", false, `Download failed: ${message}`);
7982
}
@@ -82,7 +85,10 @@ const RETRYABLE_NETWORK_CODES = new Set(["ECONNRESET", "ECONNREFUSED", "ETIMEDOU
8285

8386
function isRetryableNetworkCause(error: unknown): boolean {
8487
const message = error instanceof Error ? error.message : String(error);
85-
const code = (error as NodeJS.ErrnoException | undefined)?.code ?? "";
88+
const code =
89+
typeof error === "object" && error !== null && "code" in error && typeof error.code === "string"
90+
? error.code
91+
: "";
8692
return (
8793
RETRYABLE_NETWORK_CODES.has(code) ||
8894
code.startsWith("UND_ERR_") ||

0 commit comments

Comments
 (0)