Repository navigation
Conversation
…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.
|
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On top of #1776. A
RecipherErrornow carries the engine's whole diagnostic, the way the Go SDK'sDiagnosticdoes, 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 (reasonandfield) and dropped the causes.The package is still private and takes no changeset.
Changes
helpandurlare properties of their own.messageis 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.fieldsholds every structured field the engine gives (ErrorPayload::payload), bysnake_casename.reasonandfieldare still there, typed, andrecordis unchanged.causeslists 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 textan 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).recipher::…codes). It reads the Rust and TypeScript sources, checks each code's form with the engine'sdiagnostic::is_code_of, and fails when a code is added without being added to the list.serde-jsonfeature is on, sofieldscrosses as a plain object.thiserroris 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 --checkandcargo 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.tsis regenerated bybuild:debugand committed.Not run: the release build, and anything on Linux or Windows. CI is the check for those.
Review notes
urlis alwaysundefinedtoday. No engine error that the SDK can reach sets one. Engine errors have codes but no documentation links — decide the URL format and give every code a page #1790 is the engine issue for deciding the URL format and giving each code a page. The property is here so the link appears with no SDK change when the engine has it.reasonandfieldnow exist twice, as typed properties and insidefields. I kept the typed ones because the record refusals set them and the tests read them. Dropping them in favour offieldsalone, as Go does, is a small follow-up if preferred.severity. Go'sDiagnostichas one. AnErris always an error here, so I left it out.stack-guest-abi. Engine errors have codes but no documentation links — decide the URL format and give every code a page #1790 proposes moving it tostack-profileso both SDKs share it.fromNativereads an error without them.Related