unslothai/unsloth · error · Error
${parsed.error.message || "Stream error"}
Error message
${parsed.error.message || "Stream error"} What it means
Thrown when a parsed SSE data payload contains an error object — the server pushed a mid-stream error event ({error: {message}}) instead of an OpenAI chat chunk. The thrown message is the server-provided error.message, falling back to 'Stream error'. This fires after the stream already started, so partial output may exist.
Source
Thrown at studio/frontend/src/features/chat/api/chat-api.ts:1378
const dataLines = parseSseEvent(rawEvent);
if (dataLines.length === 0) {
separatorIndex = buffer.search(/\r?\n\r?\n/);
continue;
}
const dataText = dataLines.join("\n");
if (dataText === "[DONE]") {
completed = true;
sawTerminalSignal = true;
throwIfReasoningOnlyLength();
return;
}
const parsed = JSON.parse(dataText) as
| OpenAIChatChunk
| { type?: string; content?: string; error?: { message?: string } };
if ("error" in parsed && parsed.error) {
throw new Error(parsed.error.message || "Stream error");
}
// Tool status events are custom SSE payloads, not OpenAI chunks
if ("type" in parsed && parsed.type === "tool_status") {
yield {
_toolStatus: parsed.content ?? "",
} as unknown as OpenAIChatChunk;
separatorIndex = buffer.search(/\r?\n\r?\n/);
continue;
}
// Diffusion frame: a per-step canvas snapshot. Custom SSE payload (not an OpenAI chunk) with
// no assistant text, surfaced as a transient marker for the in-place renderer, never the transcript.
if ("type" in parsed && parsed.type === "diffusion_frame") {
yield {
_diffusionFrame: parsed,
} as unknown as OpenAIChatChunk;
separatorIndex = buffer.search(/\r?\n\r?\n/);
continue;
}View on GitHub (pinned to 203007d190)
Solutions
- Read the thrown message — it is the server's own description of the failure.
- Retry once; transient upstream overload often clears.
- If it is a moderation/content error, change the prompt rather than retrying.
- Check backend logs for the upstream error that was forwarded.
Defensive patterns
Strategy: try-catch
Type guard
function isStreamErrorEvent(parsed: unknown): parsed is { error: { message?: string } } {
return typeof parsed === 'object' && parsed !== null && 'error' in parsed && !!(parsed as any).error;
} Try / catch
try { for await (const c of stream) render(c); }
catch (e) {
const msg = e instanceof Error ? e.message : '';
if (/overloaded|rate/i.test(msg)) return retryOnce();
showError(msg || 'Stream error');
} Prevention
- Treat mid-stream error events as user-visible failures, not silent EOF.
- Classify message text (moderation vs overload) before choosing retry vs prompt change.
- Log the raw error event for backend correlation.
When it happens
Trigger: The backend streams normally for a while, then emits a JSON event containing an error key — e.g. upstream provider failure, content filter, or model crash reported asynchronously over the same SSE channel.
Common situations: Upstream provider errors surfacing mid-stream (overloaded, context exceeded mid-conversation, moderation trigger); gateway converting a late upstream 5xx into an in-stream error event.
Related errors
- {path}: not valid JSON: {exc}
- ChatGPT returned a malformed stream.
- ChatGPT stream ended before completion.
- Stream response missing body
- Response interrupted: the connection dropped before the mode
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/2b8f552f9d2e9dcf.
Report an issue: GitHub.