Skip to content

feat(recipher-js): an error keeps the engine's help, URL, fields and causes - #1791

Draft
coderdan wants to merge 1 commit into
feat/recipher-js-recordsfrom
feat/recipher-js-diagnostics
Draft

coderdan wants to merge 1 commit into
feat/recipher-js-recordsfrom
feat/recipher-js-diagnostics

Conversation

@coderdan

Copy link
Copy Markdown
Contributor

Summary

On top of #1776. A RecipherError now carries the engine's whole diagnostic, the way the Go SDK's Diagnostic does, instead of a code and a message with the help glued onto it.

The engine's errors are miette diagnostics: each has a stable code, and many have a help text, structured fields and a chain of causes. Before this change the TypeScript SDK kept the code, appended the help to message, read two of the fields (reason and field) and dropped the causes.

The package is still private and takes no changeset.

Changes

  • help and url are properties of their own. message is the engine's one line and nothing else, so a caller can show the help separately or leave it out. toString() prints the help on a second line.
  • fields holds every structured field the engine gives (ErrorPayload::payload), by snake_case name. reason and field are still there, typed, and record is unchanged.
  • causes lists the errors behind this one, outermost first. A cause that is one of the engine's own errors gives its code and message. A cause from another library gives the fixed text an error from another library, and its own message is never copied: that text is not ours and can quote a value. This is the rule the Go guest's encoder follows (packages/stack-guest-abi/src/last_error.rs).
  • A test lists every code the SDK gives an error of its own (39 recipher::… codes). It reads the Rust and TypeScript sources, checks each code's form with the engine's diagnostic::is_code_of, and fails when a code is added without being added to the list.
  • napi's serde-json feature is on, so fields crosses as a plain object. thiserror is a dev-dependency for the test's probe errors. Both were already in the lockfile.

The README's error section now has an example and a table of the properties.

Verification

Run locally in a worktree, with the debug addon rebuilt:

  • cargo test --locked --all-features: 39 and 4 passed.
  • cargo fmt --all --check and cargo clippy --locked --all-targets --all-features -- -D warnings: clean.
  • vitest run: 29 passed. vitest run --config vitest.addon.config.ts: 76 passed.
  • tsc --noEmit: clean. Biome: clean.
  • native.d.ts is regenerated by build:debug and committed.

Not run: the release build, and anything on Linux or Windows. CI is the check for those.

Review notes

Related

…causes

A RecipherError held the engine's code and a message with the help
appended to it, and two of the structured fields. It now holds the whole
diagnostic, as the Go SDK's does: help and url as properties of their own,
every structured field, and the cause chain. A cause from another library
is named as one and its message is never copied. A test lists every code
the SDK gives an error of its own and checks each one's form.
@changeset-bot

changeset-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8676fe5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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