{"record":{"id":"45537e8f839a00fc","repo":"janhq/jan","slug":"error-message-index","errorCode":null,"errorMessage":"error.message","messagePattern":"error\\.message","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extensions/llamacpp-extension/src/index.ts","lineNumber":2462,"sourceCode":"\n        buffer += decoder.decode(value, { stream: true })\n\n        // Process complete lines in the buffer\n        const lines = buffer.split('\\n')\n        buffer = lines.pop() || '' // Keep the last incomplete line in the buffer\n\n        for (const line of lines) {\n          const trimmedLine = line.trim()\n          if (!trimmedLine || trimmedLine === 'data: [DONE]') {\n            continue\n          }\n\n          if (trimmedLine.startsWith('data: ')) {\n            jsonStr = trimmedLine.slice(6)\n          } else if (trimmedLine.startsWith('error: ')) {\n            jsonStr = trimmedLine.slice(7)\n            const error = JSON.parse(jsonStr)\n            throw new Error(error.message)\n          } else {\n            // it should not normally reach here\n            throw new Error('Malformed chunk')\n          }\n          try {\n            const data = JSON.parse(jsonStr)\n            const chunk = data as chatCompletionChunk\n\n            yield chunk\n          } catch (e) {\n            logger.error('Error parsing JSON from stream or server error:', e)\n            // re‑throw so the async iterator terminates with an error\n            throw e\n          }\n        }\n      }\n    } finally {\n      reader.releaseLock()","sourceCodeStart":2444,"sourceCodeEnd":2480,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/extensions/llamacpp-extension/src/index.ts#L2444-L2480","documentation":"Thrown while parsing the SSE stream when a line begins with 'error: ' — the extension extracts the JSON payload after the prefix, parses it, and re-throws the server-supplied error.message. This propagates llama.cpp's own in-stream error to the caller.","triggerScenarios":"The llama.cpp server sends an SSE line 'error: {\"message\": ...}' mid-stream — e.g. inference aborted, context overflow discovered during generation, or the model crashed mid-completion.","commonSituations":"Long generations exceeding context after streaming began; server-side abort (client disconnect handling, load shutdown); inference runtime errors (CUDA OOM mid-token).","solutions":["Read error.message for the server's actual reason and address it (usually context overflow or server shutdown).","Reduce max_tokens/prompt size if the message indicates context limits.","Check llama.cpp server logs for the corresponding internal error.","Implement client retry with backoff if the server was restarting under load."],"exampleFix":"// before\n} else if (trimmedLine.startsWith('error: ')) {\n  const error = JSON.parse(trimmedLine.slice(7))\n  throw new Error(error.message)\n}\n// after\n} else if (trimmedLine.startsWith('error: ')) {\n  const error = JSON.parse(trimmedLine.slice(7))\n  const err = new Error(error.message || 'Unknown llamacpp stream error')\n  err.payload = error\n  throw err\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"function isStreamErrorEvent(e: unknown): e is Error & { payload?: { message: string } } {\n  return e instanceof Error && typeof (e as any).payload === 'object'\n}","tryCatchPattern":"try {\n  for await (const chunk of stream) yield chunk\n} catch (e) {\n  if (/context|token|OOM|memory/i.test(String((e as Error).message))) {\n    // surface actionable guidance: reduce context or restart engine\n  }\n  throw e\n}","preventionTips":["Cap prompt + max_tokens below the model's context window.","Monitor engine memory; CUDA OOM mid-stream throws these errors.","Handle stream errors per-request, not globally, to preserve other sessions.","Check server logs whenever error.message is opaque."],"tags":["streaming","sse","llamacpp","server-error"],"backgroundTag":"upstream-api-error","analyzedSha":"7205d770c1e097c3daf35a911176410e93bc5564","analyzedAt":"2026-09-17T14:27:30.100Z","contentChangedAt":"2026-09-17T14:27:30.100Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}