Skip to content

[miniflare] Preserve binding error codes in local development - #16499

Merged
edmundhung merged 2 commits into
cloudflare:mainfrom
dinasaur404:fix/preserve-binding-error-codes
Oct 27, 2026
Merged

edmundhung merged 2 commits into
cloudflare:mainfrom
dinasaur404:fix/preserve-binding-error-codes

Conversation

@dinasaur404

@dinasaur404 dinasaur404 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Errors from Artifacts (and other bindings) lose code and numericCode in local development. Developers can only branch on message text, so code that works in production can fail locally.

What was broken

Comparison for the same calls (get() on a missing repo, invalid name, list({ limit: 0 })):

Path Before After
Production (Worker on Cloudflare) name: "ArtifactsError", code: "NOT_FOUND", numericCode: 10200 unchanged
wrangler dev with remote: true, inside the Worker name: "Error", message: "ArtifactsError: Repository not found…", no code code and numericCode kept, clean message, name: "Error"
getPlatformProxy() with remote: true same as above code and numericCode kept, clean message
Miniflare#getBindings() with a local binding same as above identical to production, including name: "ArtifactsError"

Why

Three internal workers pass errors between Workers. They use compatibility dates from before workerd's enhanced_error_serialization behavior, so they keep only the message text and fold the name into it:

  • the remote-bindings proxy server (packages/remote-bindings/src/start-remote-proxy-session.ts)
  • the remote-proxy client (packages/miniflare/src/plugins/shared/constants.ts)
  • the entry worker that hosts ProxyServer for Node callers (packages/miniflare/src/plugins/core/index.ts)

Miniflare already enables this flag for local D1 for the same reason.

Separately, the devalue Error reducer used by the Node proxy (packages/miniflare/src/workers/core/devalue.ts) sent only name, message, stack and cause. It now also sends own properties with primitive values (string, number, boolean or null) and a custom error name. It skips non-primitive values so they can't make an error unserialisable. Errors without extra properties keep the old encoding.

Known limitation

Inside a Worker, remote-binding errors are still named Error. capnweb rebuilds unrecognized error types as plain Error and doesn't restore name. Code should branch on code. That's fixed separately in cloudflare/capnweb#289. With both changes, remote: true errors match production exactly, including name: "ArtifactsError"; I verified this end to end.

Testing

  • New unit tests: devalue error round-trips (custom name and properties, built-in constructors, unchanged encoding without extra properties); Node proxy keeps name, code and numericCode thrown by an RPC binding. All three behavior tests fail without the source changes.
  • Updated the raw-TCP opt-in assertions in remote-bindings-connect.spec.ts. experimental is still opt-in only.
  • miniflare: full suite 1,664 passed (3 skipped) after the assertion update. remote-bindings: 31 passed. wrangler remote-bindings and startDevWorker tests: 160 passed. tsc, oxlint --type-aware and oxfmt clean.
  • Manual check against production with read-only calls, before and after this change, through wrangler dev with remote: true, getPlatformProxy() and wrangler dev --remote. Results are in the table.

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bug fix that restores production error behavior in local development

Errors from remote bindings and Node.js binding proxies lost custom
properties such as Artifacts' `code` and `numericCode`, and had their
name folded into the message. Enable `enhanced_error_serialization` on
the internal workers that relay these errors, and keep primitive own
properties and custom names in the devalue `Error` reducer.
@changeset-bot

changeset-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 74baf24

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

This PR includes changesets to release 8 packages
Name Type
miniflare Patch
wrangler Patch
@cloudflare/deploy-helpers Patch
@cloudflare/pages-shared Patch
@cloudflare/remote-bindings Patch
@cloudflare/runtime-types Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-plugin 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

Hi @dinasaur404. Thanks for taking the time to contribute to Workers SDK.

This PR has been automatically closed because you are not currently a registered (vouched) collaborator for this repository.

AI tools now let our team generate proposed code changes quickly. Reviewing changes, checking that they solve the right problem, and maintaining code quality over time still take substantial care and effort. We therefore limit PRs to registered collaborators so we can focus that effort where it is most useful.

For the majority of external contributors, the most effective way to help is through issues: describing a problem or use case, providing a minimal reproduction, investigating its cause, or helping us verify a fix. Those contributions help us understand what needs to change and are very welcome.

We will take an initial look at this PR and decide whether it is something we want to invest time in reviewing and maintaining. We may reopen it if we decide to proceed, but we cannot guarantee that it will be reopened or receive a full review.

@github-actions github-actions Bot closed this Oct 26, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Oct 26, 2026
@workers-devprod
workers-devprod requested review from a team and edmundhung and removed request for a team October 26, 2026 21:08
@workers-devprod

workers-devprod commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

devin-ai-integration[bot]

This comment was marked as resolved.

@clanky-the-clanker

clanky-the-clanker Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

✅ Approved — No issues found. The flag changes are consistent across the three workers, and the error serialization change is narrow and covered by tests.

The decision is advisory: this comment never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low. The changeset describes the combined fix and requests patch releases for the affected packages.


🔒 Security: ✅ LGTM

No security concerns. Revived error properties are limited to primitive values and set with Object.defineProperty as own properties of the error. They can't change the prototype or override message, stack or cause.


📖 AGENTS.md: ✅ LGTM

The change follows the repository conventions.


📋 Code Quality: ✅ LGTM

The compatibility-flag additions match across the three internal workers. The devalue Error reducer and reviver round-trip correctly, and errors without extra properties keep their old encoding. The reviver checks property types and protects message, stack and cause. Tests cover all three behaviour changes.


⚡ Performance: ✅ LGTM

Serializing an error now loops over its few own property names, which costs very little. The flag changes add nothing to hot paths.


📝 Documentation: ✅ LGTM

The changeset and the code comments describe the change accurately.


Reviewed commit: 74baf24d

@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@16499

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@16499

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@16499

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@16499

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@16499

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@16499

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@16499

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@16499

miniflare

npm i https://pkg.pr.new/miniflare@16499

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@16499

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@16499

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@16499

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@16499

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@16499

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@16499

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@16499

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@16499

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@16499

wrangler

npm i https://pkg.pr.new/wrangler@16499

commit: 74baf24

@edmundhung edmundhung added ci:e2e Run wrangler + vite-plugin E2E tests on a pull request ci:run-remote-tests Run remote/E2E tests that require Cloudflare API credentials labels Oct 27, 2026
…zation

Match workerd's enhanced_error_serialization, which includes all own
properties, by using Object.getOwnPropertyNames instead of Object.keys.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

Devin Review

Comment thread packages/miniflare/src/workers/core/devalue.ts
Comment thread packages/miniflare/src/workers/core/devalue.ts

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Oct 27, 2026
@edmundhung edmundhung removed ci:e2e Run wrangler + vite-plugin E2E tests on a pull request ci:run-remote-tests Run remote/E2E tests that require Cloudflare API credentials labels Oct 27, 2026
@edmundhung
edmundhung enabled auto-merge (squash) October 27, 2026 15:11
@edmundhung
edmundhung merged commit f3c13b3 into cloudflare:main Oct 27, 2026
102 of 121 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants