(cause: unknown)
| 66 | } |
| 67 | |
| 68 | export function openCodeRuntimeErrorDetail(cause: unknown): string { |
| 69 | if (OpenCodeRuntimeError.is(cause)) return cause.detail; |
| 70 | if (cause instanceof Error && cause.message.trim().length > 0) return cause.message.trim(); |
| 71 | if (cause && typeof cause === "object") { |
| 72 | // SDK v2 throws { response, request, error? } shapes — extract what's useful |
| 73 | const anyCause = cause as Record<string, unknown>; |
| 74 | const status = (anyCause.response as { status?: number } | undefined)?.status; |
| 75 | const body = anyCause.error ?? anyCause.data ?? anyCause.body; |
| 76 | const encodedBody = encodeJsonStringForDiagnostics(body ?? cause); |
| 77 | if (encodedBody) { |
| 78 | return `status=${status ?? "?"} body=${encodedBody}`; |
| 79 | } |
| 80 | } |
| 81 | return String(cause); |
| 82 | } |
| 83 | |
| 84 | export const runOpenCodeSdk = <A>( |
| 85 | operation: string, |
no test coverage detected