Skip to content

fix(core): surface NamedError detail without doubling the tag#31564

Open
albertdbio wants to merge 1 commit into
anomalyco:devfrom
albertdbio:fix/named-error-message
Open

fix(core): surface NamedError detail without doubling the tag#31564
albertdbio wants to merge 1 commit into
anomalyco:devfrom
albertdbio:fix/named-error-message

Conversation

@albertdbio

Copy link
Copy Markdown

Issue for this PR

Closes #31414

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

NamedError's constructor called super(name), so every instance had Error.message === Error.name. Since Cause.pretty and Error.prototype.toString() render an error as ${name}: ${message}, this produced output like ProviderAuthError: ProviderAuthError and hid the actual data.message.

This sets Error.message to the human detail — data.message when the data carries a string message, otherwise empty — and keeps the tag on .name. Renderers then compose ProviderAuthError: <real message> once: no doubled tag, and the detail is no longer hidden.

How did you verify your code works?

Added packages/core/test/util-error.test.ts covering both paths: an error with a message renders as "Name: message" via both toString() and Cause.pretty; one without renders as "Name" (no trailing colon, no doubled tag). bun test passes locally and bun typecheck is clean across all packages.

Screenshots / recordings

N/A — not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The NamedError constructor called super(name), so every instance had Error.message === Error.name. Cause.pretty and Error.prototype.toString() compose an error as name: message, so this produced ProviderAuthError: ProviderAuthError and hid the real data.message. Keep Error.message as the human detail (data.message when present, else empty); the tag stays on .name and renderers compose it. Adds a regression test covering both render paths.
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.

NamedError hides data.message: Error.message is set to the tag name

1 participant