earendil-works/pi · error

An unknown error occurred

Error message

An unknown error occurred

What it means

A generic fallback thrown in stream() when the mapped stopReason is 'aborted' or 'error' but no specific errorMessage was recorded anywhere in the stream. It guarantees the consumer always receives an Error with a message instead of an undefined failure.

Solutions

  1. Inspect output.errorMessage or the raw stop reason for the underlying provider error.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at packages/ai/src/api/anthropic-messages.ts:779 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/1789ea17385cae1e. Report an issue: GitHub.

Appendix: source

Thrown at packages/ai/src/api/anthropic-messages.ts:779

							output.usage.reasoning = thinkingTokens;
						}
					}
					// Anthropic doesn't provide total_tokens, compute from components
					output.usage.totalTokens =
						output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
					calculateCost(usageModel, output.usage);
				}
			}

			if (options?.signal?.aborted) {
				throw new Error("Request was aborted");
			}

			if (output.stopReason === "pending") {
				throw new Error("Anthropic stream ended without a stop reason");
			}
			if (output.stopReason === "aborted" || output.stopReason === "error") {
				throw new Error(output.errorMessage || "An unknown error occurred");
			}

			stream.push({ type: "done", reason: output.stopReason, message: output });
			stream.end();
		} catch (error) {
			for (const block of output.content) {
				delete (block as { index?: number }).index;
				// partialJson is only a streaming scratch buffer; never persist it.
				delete (block as { partialJson?: string }).partialJson;
			}
			output.stopReason = options?.signal?.aborted ? "aborted" : "error";
			output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
			stream.push({ type: "error", reason: output.stopReason, error: output });
			stream.end();
		}
	})();

	return stream;

View on GitHub (pinned to 4af9d21d3b)