Skip to content

Tunnel debug port RPC errors to callers#6507

Draft
penalosa wants to merge 4 commits intomainfrom
penalosa/debug-port-error-messages
Draft

Tunnel debug port RPC errors to callers#6507
penalosa wants to merge 4 commits intomainfrom
penalosa/debug-port-error-messages

Conversation

@penalosa
Copy link
Copy Markdown
Contributor

@penalosa penalosa commented Apr 7, 2026

Summary

  • Prefix debug port getEntrypoint() and getActor() assertion messages with jsg.Error: so they tunnel through capnp RPC instead of being sanitized to generic internal error; reference = <id> messages.

Background

The debug port is used by the dev registry to proxy service bindings and Durable Object bindings across wrangler dev / vite dev processes. When a caller references a non-existent entrypoint or DO class, the KJ assertions in the debug port handler produce descriptive errors (e.g. "Entrypoint not found"), but decodeTunneledException() treats them as internal errors and replaces the message with an opaque reference ID.

The jsg.Error: prefix marks these as user-facing errors that should be forwarded as-is, matching the pattern used elsewhere in the codebase (e.g. JSG_REQUIRE_NONNULL).

The debug port's getEntrypoint() and getActor() methods used plain
KJ_ASSERT_NONNULL for error cases (service not found, entrypoint not
found, DO class not found). KJ exceptions without a jsg. prefix get
sanitized by decodeTunneledException() into a generic
"internal error; reference = <id>" before reaching the caller.

Prefix these assertion messages with "jsg.Error:" so they tunnel
through capnp RPC and the caller receives the actual error description
(e.g. "Entrypoint not found: NonExistentEntrypoint").
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

The generated output of @cloudflare/workers-types has been changed by this PR. If this is intentional, run just generate-types to update the snapshot. Alternatively, you can download the full generated types:

Full Type Diff

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

This PR prefixes debug port assertion messages with jsg.Error: so they tunnel through capnp RPC. The tunneling mechanism itself works correctly — tunneledErrorType() will recognize the prefix and mark these as non-internal errors.

However, there's one issue that affects all the changed assertions:

  1. [MEDIUM] KJ assertion formatting artifacts leak into user-visible error messages. When KJ assertion macros have multiple arguments, extra args are formatted as ; varName = value with the variable name as a label. This means users will see messages like Service not found:; serviceName = myService instead of Service not found: myService. The JSG_REQUIRE/JSG_REQUIRE_NONNULL macros avoid this by pre-formatting with kj::str() — the same approach should be used here.

This review was generated by an AI assistant and may contain inaccuracies.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Apr 7, 2026

The review has been posted on PR #6507. Here's a summary of the finding:

[MEDIUM] KJ assertion formatting artifacts leak into user-visible error messages. The PR correctly uses the jsg.Error: prefix for tunneling, but passes extra arguments (like serviceName) as separate KJ assertion macro arguments. KJ formats these with ; varName = value labels, so users would see error messages like Service not found:; serviceName = myService instead of the cleaner Service not found: myService. The fix is to wrap the message with kj::str() to pre-format it into a single string, matching how JSG_REQUIRE_NONNULL handles this internally. I posted concrete suggestion comments on all 6 affected assertion sites.

github run

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