decolua/9router · error

AWS EventStream payload is not valid JSON (${error.message})

Error message

AWS EventStream payload is not valid JSON (${error.message})

What it means

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.

Source

Thrown at open-sse/executors/kiro.js:1278

      const bytes = data.subarray(offset, offset + valueLength);
      headers[name] = type === 7 ? decoder.decode(bytes) : bytes;
      offset += valueLength;
    } else if (type === 9) {
      requireBytes(16);
      offset += 16;
    } else {
      throw new Error(`AWS EventStream header ${name} has unknown type ${type}`);
    }
  }

  const payloadBytes = data.subarray(headerEnd, totalLength - 4);
  if (payloadBytes.byteLength === 0) return { headers, payload: null };
  const payloadText = decoder.decode(payloadBytes);
  if (!payloadText.trim()) return { headers, payload: null };
  try {
    return { headers, payload: JSON.parse(payloadText) };
  } catch (error) {
    throw new Error(`AWS EventStream payload is not valid JSON (${error.message})`);
  }
}

export default KiroExecutor;

View on GitHub (pinned to 90b52e06ff)

Solutions

  1. Log payloadText (not just error.message) to see what the upstream actually sent — it usually names the real problem (quota, auth, HTML error page)
  2. Retry the request; transient upstream error frames often contain non-JSON bodies
  3. Check account quota/auth state if the payload mentions throttling or credentials
  4. Update 9router in case Kiro changed its payload encoding and the parser was adapted
  5. Bypass intermediaries that could rewrite response bodies

Example fix

// before
try { return { headers, payload: JSON.parse(payloadText) }; }
catch (error) { throw new Error(`AWS EventStream payload is not valid JSON (${error.message})`); }
// after (surface upstream text for diagnosis)
catch (error) {
  console.error('eventstream payload:', payloadText.slice(0, 500));
  throw new Error(`AWS EventStream payload is not valid JSON (${error.message})`);
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await executor.execute(req);
} catch (e) {
  if (String(e.message).includes('payload is not valid JSON')) {
    // upstream sent a non-JSON frame payload; inspect and retry/fallback
    return retryOnceThenFallback(req);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Kiro returns an internal error or throttle message as plain text; a proxy rewrites the payload bytes; a Kiro API change alters payload encoding.

Understand the failure class

Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.

Related errors


AI-assisted analysis of decolua/9router@90b52e06ff (2026-08-30). Data as JSON: /api/errors/50f14fd7a95f30c2. Report an issue: GitHub.