agent failed to parse workerd "invalid redirect value" stack: no source location
Fixes workerd's 'Response constructor: invalid redirect value' error when the stack trace carries no file or line. Tells an agent to stop following the stack and instead search its source for Response.redirect calls using an invalid status code, and to route future occurrences on the message text alone.
TL;DR: Pass a valid redirect status code (301, 302, 303, 307, or 308) to Response.redirect. workerd validates the status in native code before any JavaScript frame runs, so the thrown error carries no file or line. The fix is to find the call site by searching your source for Response.redirect instead of following the stack.
Response constructor: invalid redirect valueSteps
Search your worker source for every redirect construction:
grep -rn "Response.redirect" src worker functionsExpected: a list of files and line numbers where redirects are built.At each call site, read the status argument. Anything other than 301, 302, 303, 307, or 308 (for example 200, 201, or 404) is invalid and triggers this exact error. Expected: you find at least one call passing a non-redirect status.
Change the status to the intended redirect code, e.g. 302 for a temporary redirect or 301 for permanent. Expected: the file saves with a valid redirect status.
Reproduce locally with
wrangler devand hit the redirect path. Expected: a 3xx response in the browser or curl, and no "invalid redirect value" exception in the worker logs.Teach the agent's parser the routing rule: match on the message text /invalid redirect value/ and jump straight to the redirect-site search; never wait for stack frames that will not come. Expected: the next occurrence triages to the right file on the first pass, even with an empty stack.
Use this when
- The exact message "Response constructor: invalid redirect value" appears in workerd logs
- The stack trace is empty, or points at native code with no file or line
- A worker builds redirects with Response.redirect
- An agent's stack parser reports "no source location" for this error
Not for this skill when
- The redirect fails with a different message, e.g. an invalid URL or too many redirects
- The error comes from a fetch to an external origin rather than Response.redirect
- The stack trace DOES contain a valid file and line (follow it instead)
Variant phrasings
- workerd "Response constructor: invalid redirect value" on 301 redirect
- workerd uncaught exception: invalid redirect value
- Response.redirect throws inside a Cloudflare Worker
- redirect status invalid in worker fetch handler
Why it happens
The fetch spec only allows the five redirect status codes in the Response constructor. workerd validates the status in its native C++ layer before any JavaScript frame executes, so the TypeError it throws has no JavaScript source location attached. Most commonly an agent or developer passes 200 (meaning "OK") or a variable holding a non-redirect status.
Edge cases
- A status passed as a string can coerce oddly; keep it a number.
- If the status comes from a variable, grep will not show the value; log it once right before the redirect call to see what is actually passed.
- Shared middleware may contain several redirect helpers; check every call site, not just the first hit.
- The same error fires from the local workerd in
wrangler dev, so this rule applies in local development too.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_lXPElgGXsYX332JBcuglVQ