{"record":{"id":"af094912d6160771","repo":"Hmbown/CodeWhale","slug":"string-e-message-e","errorCode":null,"errorMessage":"String(e?.message ?? e)","messagePattern":"String\\(e\\?\\.message \\?\\? e\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"scripts/opencode-chat2responses-proxy.mjs","lineNumber":199,"sourceCode":"        const { done, value } = await reader.read();\n        if (done) break;\n        buf += decoder.decode(value, { stream: true });\n        let idx;\n        while ((idx = buf.indexOf(\"\\n\\n\")) !== -1) {\n          const chunk = buf.slice(0, idx + 2);\n          buf = buf.slice(idx + 2);\n          const translated = translateResponsesSseToChat(chunk, model);\n          if (translated) res.write(translated);\n        }\n      }\n      if (buf.trim()) {\n        const translated = translateResponsesSseToChat(buf, model);\n        if (translated) res.write(translated);\n      }\n      res.write(`data: [DONE]\\n\\n`);\n      res.end();\n    } catch (e) {\n      res.writeHead(500, { \"content-type\": \"application/json\" });\n      res.end(JSON.stringify({ error: String(e?.message ?? e).slice(0, 2000) }));\n    }\n  });\n});\n\nserver.listen(LISTEN_PORT, \"127.0.0.1\", () => {\n  console.log(`[opencode-proxy] listening on http://127.0.0.1:${LISTEN_PORT}/v1/chat/completions -> ${UPSTREAM_BASE}${UPSTREAM_PATH}`);\n  console.log(`[opencode-proxy] health: http://127.0.0.1:${LISTEN_PORT}/health`);\n});\n","sourceCodeStart":181,"sourceCodeEnd":209,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/opencode-chat2responses-proxy.mjs#L181-L209","documentation":"This is the proxy's top-level error funnel: if translating or relaying the upstream SSE stream throws, the server responds 500 with { error: <first 2000 chars of the exception message> }. The bare expression String(e?.message ?? e) is the message-extraction code, so the observed text mirrors whatever upstream/translation error occurred.","triggerScenarios":"Upstream returns non-SSE or malformed data, translateResponsesSseToChat throws on unexpected chunk shapes, the upstream request itself fails mid-stream, or an exception is thrown while writing the response.","commonSituations":"Upstream auth failure, upstream API change breaking the SSE translation, network drop between proxy and OpenAI, or a timeout aborting the fetch mid-stream.","solutions":["Check the upstream server logs and the 500 body's error text for the root cause","Verify upstream API credentials and model name","Confirm the upstream still emits Responses-style SSE that the translator understands","Retry the request; if persistent, inspect translateResponsesSseToChat against the current upstream format"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight upstream check\nconst pre = await fetch(`${UPSTREAM_BASE}/v1/chat/completions`, { method: \"POST\", headers, body: JSON.stringify({ model, messages: [], max_tokens: 1 }) });\nif (!pre.ok) throw new Error(`upstream unhealthy: ${pre.status}`);","typeGuard":null,"tryCatchPattern":"try {\n  await streamFromUpstream();\n} catch (e) {\n  console.error(\"proxy 500 origin:\", String(e?.message ?? e).slice(0, 2000));\n  // inspect upstream status/format before retrying\n}","preventionTips":["Validate upstream credentials and model names before streaming","Watch for upstream API format changes that break SSE translation","Set upstream timeouts and retries","Log the 500 body's error field — it contains the truncated root cause"],"tags":["proxy","sse","error-handling","upstream"],"backgroundTag":"upstream-api-error","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}