{"record":{"id":"2b8f552f9d2e9dcf","repo":"unslothai/unsloth","slug":"parsed-error-message-stream-error","errorCode":null,"errorMessage":"${parsed.error.message || \"Stream error\"}","messagePattern":"\\$\\{parsed\\.error\\.message \\|\\| \"Stream error\"\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"studio/frontend/src/features/chat/api/chat-api.ts","lineNumber":1378,"sourceCode":"        const dataLines = parseSseEvent(rawEvent);\n        if (dataLines.length === 0) {\n          separatorIndex = buffer.search(/\\r?\\n\\r?\\n/);\n          continue;\n        }\n\n        const dataText = dataLines.join(\"\\n\");\n        if (dataText === \"[DONE]\") {\n          completed = true;\n          sawTerminalSignal = true;\n          throwIfReasoningOnlyLength();\n          return;\n        }\n\n        const parsed = JSON.parse(dataText) as\n          | OpenAIChatChunk\n          | { type?: string; content?: string; error?: { message?: string } };\n        if (\"error\" in parsed && parsed.error) {\n          throw new Error(parsed.error.message || \"Stream error\");\n        }\n        // Tool status events are custom SSE payloads, not OpenAI chunks\n        if (\"type\" in parsed && parsed.type === \"tool_status\") {\n          yield {\n            _toolStatus: parsed.content ?? \"\",\n          } as unknown as OpenAIChatChunk;\n          separatorIndex = buffer.search(/\\r?\\n\\r?\\n/);\n          continue;\n        }\n        // Diffusion frame: a per-step canvas snapshot. Custom SSE payload (not an OpenAI chunk) with\n        // no assistant text, surfaced as a transient marker for the in-place renderer, never the transcript.\n        if (\"type\" in parsed && parsed.type === \"diffusion_frame\") {\n          yield {\n            _diffusionFrame: parsed,\n          } as unknown as OpenAIChatChunk;\n          separatorIndex = buffer.search(/\\r?\\n\\r?\\n/);\n          continue;\n        }","sourceCodeStart":1360,"sourceCodeEnd":1396,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/frontend/src/features/chat/api/chat-api.ts#L1360-L1396","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isStreamErrorEvent(parsed: unknown): parsed is { error: { message?: string } } {\n  return typeof parsed === 'object' && parsed !== null && 'error' in parsed && !!(parsed as any).error;\n}","tryCatchPattern":"try { for await (const c of stream) render(c); }\ncatch (e) {\n  const msg = e instanceof Error ? e.message : '';\n  if (/overloaded|rate/i.test(msg)) return retryOnce();\n  showError(msg || 'Stream error');\n}","preventionTips":["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."],"tags":["streaming","sse","server-error","mid-stream"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}