mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
Some checks are pending
test / affected packages (push) Waiting to run
test / unit (linux) (push) Waiting to run
check / typecheck (push) Waiting to run
deploy-files / deploy (push) Waiting to run
deploy-www / deploy (push) Waiting to run
deploy / deploy (push) Waiting to run
nix-eval / nix-eval (push) Waiting to run
publish / version (push) Waiting to run
publish / build-cli (push) Blocked by required conditions
publish / sign-cli-macos (push) Blocked by required conditions
publish / build-node-app-archive (push) Blocked by required conditions
publish / build-node-cli (map[bun_install_flags:--cpu=* host:blacksmith-4vcpu-windows-2025 target:windows-arm64]) (push) Blocked by required conditions
publish / build-node-cli (map[host:blacksmith-4vcpu-ubuntu-2404 target:linux-x64]) (push) Blocked by required conditions
publish / build-node-cli (map[host:blacksmith-4vcpu-ubuntu-2404-arm target:linux-arm64]) (push) Blocked by required conditions
publish / build-node-cli (map[host:blacksmith-4vcpu-windows-2025 target:windows-x64]) (push) Blocked by required conditions
publish / build-node-cli (map[host:macos-26 target:darwin-arm64]) (push) Blocked by required conditions
publish / sign-cli-windows (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--cpu=* host:windows-2025 platform_flag:--win --arm64 target:aarch64-pc-windows-msvc]) (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=arm64 host:macos-26 platform_flag:--mac --arm64 target:aarch64-apple-darwin]) (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=x64 host:macos-26-intel platform_flag:--mac --x64 target:x86_64-apple-darwin]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:x86_64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404-arm platform_flag:--linux --arm64 target:aarch64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-windows-2025 platform_flag:--win target:x86_64-pc-windows-msvc]) (push) Blocked by required conditions
publish / publish (push) Blocked by required conditions
publish / notify-discord-v2 (push) Blocked by required conditions
test / unit (windows) (push) Waiting to run
test / build (linux) (push) Waiting to run
test / build (windows) (push) Waiting to run
test / e2e (linux, app-1) (push) Blocked by required conditions
test / e2e (linux, app-2) (push) Blocked by required conditions
test / e2e (linux, app-components) (push) Blocked by required conditions
test / e2e (linux, session-ui-components) (push) Blocked by required conditions
test / e2e (windows, app-1) (push) Blocked by required conditions
test / e2e (windows, app-2) (push) Blocked by required conditions
test / e2e (windows, app-components) (push) Blocked by required conditions
test / e2e (windows, session-ui-components) (push) Blocked by required conditions
test / e2e (linux) (push) Blocked by required conditions
test / e2e (windows) (push) Blocked by required conditions
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
export interface RetryOptions {
|
|
attempts?: number
|
|
delay?: number
|
|
factor?: number
|
|
maxDelay?: number
|
|
retryIf?: (error: unknown) => boolean
|
|
}
|
|
|
|
const transientMessages = [
|
|
"load failed",
|
|
"network connection was lost",
|
|
"network request failed",
|
|
"failed to fetch",
|
|
"econnreset",
|
|
"econnrefused",
|
|
"epipe",
|
|
"etimedout",
|
|
"socket hang up",
|
|
]
|
|
|
|
// Generated clients wrap fetch failures as ClientError("Transport", { cause }) and Bun/Node put the
|
|
// network detail in `code`, so the transient signal may sit anywhere along the cause chain.
|
|
function isTransientError(error: unknown, depth = 0): boolean {
|
|
if (!error) return false
|
|
const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : ""
|
|
// oxlint-disable-next-line no-base-to-string -- Error input is intentionally normalized for message matching.
|
|
const message = `${String(error instanceof Error ? error.message : error)} ${code}`.toLowerCase()
|
|
if (transientMessages.some((item) => message.includes(item))) return true
|
|
if (!(error instanceof Error) || depth >= 5) return false
|
|
return isTransientError(error.cause, depth + 1)
|
|
}
|
|
|
|
export async function retry<T>(operation: () => Promise<T>, options: RetryOptions = {}): Promise<T> {
|
|
const attempts = options.attempts ?? 3
|
|
const delay = options.delay ?? 500
|
|
const factor = options.factor ?? 2
|
|
const maxDelay = options.maxDelay ?? 10_000
|
|
const retryIf = options.retryIf ?? isTransientError
|
|
let lastError: unknown
|
|
|
|
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
try {
|
|
return await operation()
|
|
} catch (error) {
|
|
lastError = error
|
|
if (attempt === attempts - 1 || !retryIf(error)) throw error
|
|
await new Promise((resolve) => setTimeout(resolve, Math.min(delay * Math.pow(factor, attempt), maxDelay)))
|
|
}
|
|
}
|
|
throw lastError
|
|
}
|