Error fixes / Cloudflare
Cloudflare
Cloudflare Error 1101: Worker threw an exception
The Worker script threw, and the visitor sees Cloudflare's error page.
The error
Error 1101: Worker threw a JavaScript exception
What it means
Error 1101 means your code raised an exception that was not caught. The visitor does not see the stack. You do, in Workers logs, if observability is enabled. Typical throws in a new Worker are a missing binding (env.DB is undefined), a JSON parse of an empty body, or reading a property of a null row from D1.
Fix
- Turn on Workers logs and traces in wrangler.jsonc. The logs flag and the traces flag are separate.
- Reproduce the request, then read the exception message. Fix that line. Do not guess from the 1101 page alone.
- If the message says a binding is undefined, the name in wrangler.jsonc must match env.THAT_NAME exactly, and you need a new deployment after changing it.
- Catch expected failures, such as bad JSON, and return a 400 with a short body. Let unexpected errors stay visible in logs.
- Do not catch everything and return a 200. You will hide the next 1101.
Prompt
Fix prompt
Visitors see Cloudflare Error 1101, Worker threw a JavaScript exception. Enable observability logs and traces. Find the throw from the route I name, or from the most recent stack if I paste it. Guard missing JSON and null database rows. If a binding is undefined, correct the binding name rather than swallowing the error. Do not print secrets in the log. Return a proper status code for bad input. Show me the stack line you fixed.
Questions
Where is the real stack trace?
In Workers logs for that script, not on the public error page. Enable logs first, then replay the request. wrangler tail can stream them during development.
The Worker runs locally and throws in production. Why?
A binding or secret exists in .dev.vars or the local state and was never set on the deployed script. Compare env names. Secrets are per script, set with wrangler secret put.
Can I hide 1101 with a custom error page and ignore the bug?
A branded page is fine for visitors. You still need the log, or the next request fails the same way.