Cloudflare Error 1101 "Worker threw exception" (and 1102 resource limits)
A Cloudflare Worker sits in front of the site, and it crashed. Visitors see “Error 1101: Worker threw exception”. The real error message is not on the page: it is in the Worker’s logs.
See the real error
# Stream live logs and exceptions from a deployed Worker
npx wrangler tail my-worker --format pretty
# Then reproduce the failing request in another terminal
curl -s https://app.example.com/the/failing/path -o /dev/null -w '%{http_code}\n'
Workers Logs (enable observability in the Wrangler config) keeps exceptions so you can search them later instead of only watching live.
Frequent causes of 1101
- Reading a property of
undefined: a missing header, query parameter, environment variable or binding. Check the binding names in your Wrangler config match the code. JSON.parseon a non-JSON body: an upstream returned an HTML error page. See Unexpected token in JSON.- Using a Response body twice:
response.json()afterresponse.text()throws. Clone it first. - An unhandled promise rejection from a
fetchto an origin that is down. See TypeError: fetch failed. - Node-only APIs without the
nodejs_compatcompatibility flag. - Returning something that is not a Response, such as an object or
undefined.
Catch it and fail gracefully
export default {
async fetch(request, env, ctx) {
try {
return await handle(request, env, ctx);
} catch (err) {
console.error('handler failed', err && err.stack);
return new Response('Something went wrong', { status: 500 });
}
},
};
For a Worker on a route in front of an origin, ctx.passThroughOnException() tells Cloudflare to send the request to the origin as if the Worker were not there when it throws. That keeps the site up while you fix the bug, but it skips any auth or rewriting the Worker does, so use it only where that is safe.
Error 1102: exceeded resource limits
- CPU time: time spent actually computing, not waiting on
fetch. Heavy JSON parsing, crypto in loops, image work and big regexes add up. Check the CPU time chart in the Worker’s metrics and your plan’s limit. - Memory: each Worker instance has a fixed memory limit (128 MB). Buffering a large response with
await res.text()instead of streaming it is a common cause. - Fixes: stream bodies, cache computed results, move heavy work to a queue or a scheduled job, and avoid catastrophic regex backtracking (test patterns in the regex tester).
Related
All Cloudflare error codes · TypeError: fetch failed · Unexpected token in JSON · Unexpected end of JSON input · JavaScript heap out of memory · Cloudflare Error 1033 · JSON formatter
Questions
What does Cloudflare error 1101 mean?
A Cloudflare Worker handling the request threw an uncaught exception or returned a rejected promise.
How do I see why my Worker threw?
Run npx wrangler tail for the Worker (or open its Logs in the dashboard), reproduce the request, and read the exception and stack trace.
What is Cloudflare error 1102?
The Worker exceeded its resource limits: usually CPU time per request, sometimes memory.
Can I make the site work while the Worker is broken?
For a route Worker in front of an origin, ctx.passThroughOnException() sends the request to the origin when the Worker throws. Only use it if skipping the Worker is safe.
Does waiting on fetch count towards CPU time?
No. CPU time counts computation, not time spent waiting for network responses.
Published .