{"record":{"id":"50f14fd7a95f30c2","repo":"decolua/9router","slug":"aws-eventstream-payload-is-not-valid-json-error","errorCode":null,"errorMessage":"AWS EventStream payload is not valid JSON (${error.message})","messagePattern":"AWS EventStream payload is not valid JSON \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"open-sse/executors/kiro.js","lineNumber":1278,"sourceCode":"      const bytes = data.subarray(offset, offset + valueLength);\n      headers[name] = type === 7 ? decoder.decode(bytes) : bytes;\n      offset += valueLength;\n    } else if (type === 9) {\n      requireBytes(16);\n      offset += 16;\n    } else {\n      throw new Error(`AWS EventStream header ${name} has unknown type ${type}`);\n    }\n  }\n\n  const payloadBytes = data.subarray(headerEnd, totalLength - 4);\n  if (payloadBytes.byteLength === 0) return { headers, payload: null };\n  const payloadText = decoder.decode(payloadBytes);\n  if (!payloadText.trim()) return { headers, payload: null };\n  try {\n    return { headers, payload: JSON.parse(payloadText) };\n  } catch (error) {\n    throw new Error(`AWS EventStream payload is not valid JSON (${error.message})`);\n  }\n}\n\nexport default KiroExecutor;\n","sourceCodeStart":1260,"sourceCodeEnd":1283,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/open-sse/executors/kiro.js#L1260-L1283","documentation":"After the header section, an EventStream frame's remaining bytes are the payload. parseEventFrame() decodes them as UTF-8 and expects JSON; if JSON.parse throws, it wraps the parse error message in this error. The frame arrived structurally intact (CRC checks passed) but its payload is not the JSON the Kiro executor expects.","triggerScenarios":"A Kiro EventStream frame whose payload bytes are not JSON — e.g. the upstream serializing an error/rate-limit notice as plain text inside a frame, an HTML error page fragment, or a binary payload variant.","commonSituations":"Kiro returns an internal error or throttle message as plain text; a proxy rewrites the payload bytes; a Kiro API change alters payload encoding.","solutions":["Log payloadText (not just error.message) to see what the upstream actually sent — it usually names the real problem (quota, auth, HTML error page)","Retry the request; transient upstream error frames often contain non-JSON bodies","Check account quota/auth state if the payload mentions throttling or credentials","Update 9router in case Kiro changed its payload encoding and the parser was adapted","Bypass intermediaries that could rewrite response bodies"],"exampleFix":"// before\ntry { return { headers, payload: JSON.parse(payloadText) }; }\ncatch (error) { throw new Error(`AWS EventStream payload is not valid JSON (${error.message})`); }\n// after (surface upstream text for diagnosis)\ncatch (error) {\n  console.error('eventstream payload:', payloadText.slice(0, 500));\n  throw new Error(`AWS EventStream payload is not valid JSON (${error.message})`);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await executor.execute(req);\n} catch (e) {\n  if (String(e.message).includes('payload is not valid JSON')) {\n    // upstream sent a non-JSON frame payload; inspect and retry/fallback\n    return retryOnceThenFallback(req);\n  }\n  throw e;\n}","preventionTips":["Log the decoded payload text on failure to identify the upstream's real message","Monitor account quota/auth state — upstream error frames are often the root cause","Keep the executor updated for payload-encoding changes"],"tags":["kiro","eventstream","json-parse","upstream-error"],"backgroundTag":"invalid-json-response","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}