Skip to content

Preserve the name of error types that can't be reconstructed - #289

Open
dinasaur404 wants to merge 1 commit into
cloudflare:mainfrom
dinasaur404:fix/preserve-custom-error-names
Open

dinasaur404 wants to merge 1 commit into
cloudflare:mainfrom
dinasaur404:fix/preserve-custom-error-names

Conversation

@dinasaur404

Copy link
Copy Markdown

Errors whose type capnweb can't reconstruct (anything other than the built-in error classes) arrive as plain Error with name: "Error". Own properties like code already survive, but the original name is lost. workerd keeps the name when it passes these errors between Workers, so capnweb behaves differently from the platform it runs alongside.

This shows up in Wrangler's remote bindings, which use capnweb between the local and remote proxy workers. A Cloudflare Artifacts binding throws ArtifactsError in production, but in wrangler dev with remote: true the error arrives as Error.

Change

When the receiver falls back to Error for an unknown type, set name to the sender's value as a non-enumerable own property. The object is still a real Error with Error.prototype, so instanceof checks and type safety don't change.

Names that resolve to Object.prototype members (for example constructor or __proto__) still become Error, so the existing type-confusion guarantees and test still hold.

Testing

  • New test: a custom ArtifactsError subclass with code and numericCode round-trips with its name, stays instanceof Error with Error.prototype, keeps name out of Object.keys, and String(error) gives "ArtifactsError: …". It fails without the change.
  • node project: 422 passed. workerd project: 225 passed. The browser projects weren't run locally because Playwright browsers aren't installed.
  • tsc --noEmit reports the same 44 errors as main, none new.
  • End to end: bundled this build into Wrangler's remote-bindings proxy alongside [miniflare] Preserve binding error codes in local development workers-sdk#16499 and called a production Artifacts binding with remote: true. Errors came back as { name: "ArtifactsError", code: "NOT_FOUND", numericCode: 10200 }, identical to production.

@changeset-bot

changeset-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 87517dd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
capnweb Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/capnweb@289
npm i https://pkg.pr.new/cloudflare/capnweb/capnweb-validate@289

commit: 87517dd

@clanky-the-clanker

Copy link
Copy Markdown

This pull request was not reviewed automatically because its author does not have write access to this repository. A maintainer with write access can start a review by commenting clanky review (or clanker review or @clanky-the-clanker review), optionally followed by instructions (e.g. clanky review focus on the retry logic).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant