earendil-works/pi · error · TypeError

Assistant error messages must not be empty

Error message

Assistant error messages must not be empty

What it means

An assistant message with stopReason 'error' carries an empty errorMessage. The protocol requires a non-empty error string so clients always have something to display; an empty message indicates the error path forgot to set its text.

Solutions

  1. Include a non-empty error message on assistant error messages.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/server/src/protocol.ts:317 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/54fa2ac5369311b2. Report an issue: GitHub.

Appendix: source

Thrown at packages/server/src/protocol.ts:317

		...(usage ? { usage } : {}),
		timestamp: timestamp(message.timestamp),
	} as const;
	switch (message.stopReason) {
		case "pending":
			return { ...common, status: "streaming" } satisfies AssistantTranscriptItem;
		case "stop":
		case "length":
		case "toolUse":
			return {
				...common,
				status: "complete",
				stopReason: message.stopReason,
			} satisfies AssistantTranscriptItem;
		case "deferred":
			throw new TypeError("Deferred assistant messages are not supported by protocol v1");
		case "error":
			if (message.errorMessage?.length === 0) {
				throw new TypeError("Assistant error messages must not be empty");
			}
			return {
				...common,
				status: "error",
				stopReason: "error",
				...(message.errorMessage === undefined ? {} : { errorMessage: message.errorMessage }),
			} satisfies AssistantTranscriptItem;
		case "aborted":
			return {
				...common,
				status: "aborted",
				stopReason: "aborted",
				...(message.errorMessage === undefined ? {} : { errorMessage: message.errorMessage }),
			} satisfies AssistantTranscriptItem;
		default: {
			const exhaustive: never = message.stopReason;
			return exhaustive;
		}

View on GitHub (pinned to 4af9d21d3b)