Skip to content

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

Open
albertdbio wants to merge 1 commit into
anomalyco:devfrom
albertdbio:dev
Open

fix(core): surface NamedError detail without doubling the tag#31408
albertdbio wants to merge 1 commit into
anomalyco:devfrom
albertdbio:dev

Conversation

@albertdbio

@albertdbio albertdbio commented Jun 8, 2026

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.

util/log.ts's formatError returned the bare error.message, which after the above change would drop the tag. It now uses error.toString(), which composes ${name}: ${message} and omits the ": " separator when the message is empty — so errors whose data has no message field render as just the tag rather than an empty string.

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

NamedError set Error.message to the bare tag, so Cause.pretty (which composes name and message) rendered Name: Name and hid data.message. Keep Error.message as the human detail only; the tag stays on .name and renderers compose it. log.ts formatError now renders via Error.toString() so the raw-message path no longer drops the tag. Adds a regression test covering both render paths.
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jun 8, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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