{"record":{"id":"54034e5f75d72286","repo":"linshenkx/prompt-optimizer","slug":"context-error-as-error-message-string-e","errorCode":null,"errorMessage":"${context}: ${(error as Error).message || String(error)}","messagePattern":"\\$\\{context\\}: \\$\\{\\(error as Error\\)\\.message \\|\\| String\\(error\\)\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/utils/remote-backup.ts","lineNumber":575,"sourceCode":"  context: string,\n  options?: { returnAuthFailures?: boolean },\n): Promise<Response> => {\n  let lastError: unknown\n\n  for (let attempt = 1; attempt <= GOOGLE_DRIVE_DOWNLOAD_RETRY_ATTEMPTS; attempt += 1) {\n    try {\n      const response = await fetch(url, init)\n      if (response.ok) return response\n      if (options?.returnAuthFailures && isGoogleAuthStatus(response.status)) {\n        return response\n      }\n      if (!isRetryableHttpStatus(response.status) || attempt === GOOGLE_DRIVE_DOWNLOAD_RETRY_ATTEMPTS) {\n        return assertOkResponse(response, context)\n      }\n      lastError = new Error(`${context}: ${response.status} ${response.statusText}`)\n    } catch (error) {\n      if (!isRetryableFetchError(error) || attempt === GOOGLE_DRIVE_DOWNLOAD_RETRY_ATTEMPTS) {\n        throw new Error(`${context}: ${(error as Error).message || String(error)}`, { cause: error })\n      }\n      lastError = error\n    }\n\n    await sleep(GOOGLE_DRIVE_DOWNLOAD_RETRY_BASE_DELAY_MS * attempt)\n  }\n\n  throw new Error(`${context}: ${(lastError as Error)?.message || String(lastError)}`)\n}\n\nexport const joinRemotePath = (...parts: string[]): string =>\n  parts\n    .map((part) => part.replace(/^\\/+|\\/+$/g, ''))\n    .filter(Boolean)\n    .join('/')\n\nconst normalizeObjectPath = (path: string): string => joinRemotePath(path)\n","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/utils/remote-backup.ts#L557-L593","documentation":"Thrown from the retry loop for Google Drive downloads when a fetch-level error occurs (network failure, abort, CORS) that is deemed retryable, but the retry budget is already exhausted. The original error is preserved as cause and its message is prefixed with the operation context.","triggerScenarios":"Transient network errors persisting across all retry attempts (offline machine, DNS failure, proxy blocking fetch to googleapis.com, aborted requests); the last attempt throws a retryable fetch error when attempt === GOOGLE_DRIVE_DOWNLOAD_RETRY_ATTEMPTS, forcing this immediate rethrow.","commonSituations":"Corporate proxy/SSL inspection breaking fetch to Google endpoints; flaky connectivity during large backup downloads; browser offline mode; CORS misconfiguration persisting across retries (non-transient but classified retryable).","solutions":["Check error.cause for the underlying network error and address it (DNS, proxy, TLS, offline state)","Verify network connectivity to the backup provider endpoints (curl/fetch manually)","Increase retry attempts/backoff for genuinely flaky connections via module constants if configurable","If a proxy intercepts requests, configure it to allow the Google API domains or route downloads server-side"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if (!navigator.onLine) {\n  // defer backup download until online\n}","typeGuard":null,"tryCatchPattern":"try {\n  const data = await downloadRemoteBackup(...)\n} catch (error) {\n  const cause = (error as Error).cause\n  if (cause instanceof TypeError) {\n    // network-level failure: check connectivity/proxy, retry with longer backoff\n    await waitForOnline()\n    return downloadRemoteBackup(...)\n  }\n  throw error\n}","preventionTips":["Listen to online/offline events and pause sync when offline","Inspect error.cause to distinguish network errors from HTTP errors","Whitelist provider domains through corporate proxies or route via server"],"tags":["network","retry-exhausted","google-drive","remote-backup"],"backgroundTag":"network-error-retries-exhausted","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}