fix: normalize unknown prompt errors

This commit is contained in:
Peter Steinberger
2026-01-05 23:05:57 +00:00
parent ac3dedaa1b
commit 20e00eb89b

View File

@@ -156,6 +156,17 @@ function formatUserTime(date: Date, timeZone: string): string | undefined {
} }
} }
function describeUnknownError(error: unknown): string {
if (error instanceof Error) return error.message;
if (typeof error === "string") return error;
try {
const serialized = JSON.stringify(error);
return serialized ?? "Unknown error";
} catch {
return "Unknown error";
}
}
export function buildEmbeddedSandboxInfo( export function buildEmbeddedSandboxInfo(
sandbox?: Awaited<ReturnType<typeof resolveSandboxContext>>, sandbox?: Awaited<ReturnType<typeof resolveSandboxContext>>,
): EmbeddedSandboxInfo | undefined { ): EmbeddedSandboxInfo | undefined {
@@ -601,10 +612,7 @@ export async function runEmbeddedPiAgent(params: {
} }
if (promptError && !aborted) { if (promptError && !aborted) {
const fallbackThinking = pickFallbackThinkingLevel({ const fallbackThinking = pickFallbackThinkingLevel({
message: message: describeUnknownError(promptError),
promptError instanceof Error
? promptError.message
: String(promptError),
attempted: attemptedThinking, attempted: attemptedThinking,
}); });
if (fallbackThinking) { if (fallbackThinking) {