denoland/deno · error · TypeError
Invalid response
Error message
Invalid response
What it means
trySetServeFastStaticResponse is an internal fast path used when a handler returns a response carrying Deno's private serveFast* symbol marks (set by optimized Response creation paths). It switches on an internal header-kind tag, and the default branch throws 'Invalid response' when that tag holds a value outside the known SERVE_FAST_HEADER_* enum. Standard user code cannot reach this state through public APIs; it signals an internal invariant break.
Source
Thrown at ext/http/00_serve.ts:532
op_http_set_response_body_static_with_default_header(req, body, status);
return true;
case SERVE_FAST_HEADER_CONTENT_TYPE:
op_http_set_response_body_static_with_content_type(
req,
body,
status,
response[serveFastContentTypeKey],
);
return true;
case SERVE_FAST_HEADER_NONE:
if (typeof body === "string") {
op_http_set_response_body_text(req, body, status);
} else {
op_http_set_response_body_bytes(req, body, status);
}
return true;
default:
throw new TypeError("Invalid response");
}
}
// Report an error that was thrown while a streaming response body was being
// drained. The response status/headers are already on the wire at this point,
// so the value returned from `onError` can no longer be used; we route the
// error through the handler purely so it is observed (the default handler logs
// a stack trace) instead of being silently swallowed.
function reportResponseStreamError(onError, error) {
let result;
try {
result = onError(error);
} catch (e) {
internals.log("error", "Exception in onError while handling exception", e);
return;
}
if (ObjectPrototypeIsPrototypeOf(PromisePrototype, result)) {
PromisePrototypeThen(result, undefined, (e) => {View on GitHub (pinned to 89f33cbef2)
Solutions
- Remove code that manipulates Deno internal symbols and return plain Response objects
- Update to the latest Deno patch release in case the fast-path tagging was fixed
- As a stopgap, rebuild the response before returning it: new Response(body, response) so no fast marks are present
- If it reproduces with public APIs only, file a minimal repro at github.com/denoland/deno
Defensive patterns
Strategy: try-catch
Try / catch
// Wrap the whole request path; this error indicates an internal invariant break
Deno.serve(async (req) => {
try {
return await handler(req);
} catch (err) {
return new Response("Internal Server Error", { status: 500 });
}
}); Prevention
- Never write or read Deno internal symbols (Deno[Deno.internal], serveFast* keys)
- Return responses built from public constructors only
- Pin a stable Deno release in CI to avoid nightly fast-path regressions
When it happens
Trigger: Code that manually writes Deno internal symbols (Deno[Deno.internal], serveFastStatusKey/serveFastHeaderKindKey) onto an object with an invalid header-kind value, or a regression inside Deno's optimized Response path itself.
Common situations: Experiments or monkey-patching that touch Deno.internal, or hitting a Deno bug in an unreleased/nightly build's fast-response optimization.
Related errors
- ${prefix}Linter plugin must be an object
- Already upgraded
- Already closed
- Request closed
- Return value from serve handler must be a response or a prom
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/958fd14b95b7b535.
Report an issue: GitHub.