Repository navigation
Conversation
The addon described every error twice. It sorted each engine error into one of nine kinds with a match that sent any new engine variant to `internal`, the TypeScript listed the same kinds again, and the SDK's own 39 errors were string literals at each place they were raised, tied together only by a test that scanned the source. The diagnostic's code already says what an error is, more exactly than a kind, and every language SDK meets the same choice. So `kind` is gone. The SDK's own errors are one enum that derives `thiserror::Error` and `miette::Diagnostic`, with the code, message and help on each variant, as the engine declares its errors, and an error is raised by naming a variant. One function turns any diagnostic, the engine's, the value bridge's or the SDK's own, into the object JavaScript receives. A test builds one of every variant, through a match with no wildcard, and checks each code's form and that none is used twice. Removing a property changes the outcome's shape, so the binding interface moves to 4. Closes #1800.
|
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 was referenced Nov 24, 2026
Closed
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
Closes #1800. On top of #1805.
A
RecipherErroris now the diagnostic and nothing else. Thekindproperty is gone, and a caller switches oncode. A diagnostic is the error type the Stack Encrypt engine uses: a stable code, a message, often help, structured fields and causes.Before, the addon described each error twice. It sorted every engine error into one of nine kinds by hand, and the TypeScript listed the kinds again. The SDK's own 39 errors were string literals written where each was raised. Now the SDK's own errors are one Rust enum, declared the way the engine declares its errors, and one function converts any diagnostic into the object JavaScript receives.
The package is private and unreleased, so there is no changeset.
Changes
Rust (
crate/src/)ErrorKindandkind_ofare deleted.error::Errorenum holds the SDK's own errors. It derivesthiserror::Errorandmiette::Diagnostic. Each variant has its code, its message and, where there is advice, its help. A part that varies, such as a kind name, is a field of the variant.RecipherErrorFields::diagnosticis the one conversion. The engine's errors, the value bridge'sRefusaland the SDK's own enum all go through it.engineis a short form that adds the engine's structured fields.in_recordandat_fieldset the two properties the SDK names itself.NotJson) is gone. The writer uses the enum directly.diagnostic::is_code_of("recipher", ..)and that no two variants share one.thiserrormoves from a dev-dependency to a dependency, at the version the engine uses.Cargo.lockdoes not change.TypeScript (
src/)KINDS,kindand theErrorKindexport are deleted.fromNativenow checks that the error has a stringcodeandmessage.internal(..)is nowsdkError(..). It is used only when the native build did not load or did not answer as it should.testCipherno longer raises an error of its own when reading its options throws. It passes no seed, and the native build refuses it withrecipher::testing_seed.Docs and tests
kind. Doc comments say the code instead of the kind.codeis a string and thatkinddoes not exist.What changes for a caller
kindis removed, and so is theErrorKindtype.recipher::record_name, for a record name the engine refuses as part of a field path (empty, or with a/). Before, this was the engine'sstack_encrypt::dynamic_planwith a message the SDK rewrote. The engine's message names the field even when the record name is at fault, so a code of its own is clearer.recipher::threw(a call into the native build threw) is nowrecipher::native_threw. The addon already usedrecipher::threwfor a different failure: a getter of the application's threw while a value was read. One code had two meanings.recipher::unknownis no longer raised from TypeScript. A native error with no code is refused asrecipher::outcome.help. This affectsrecipher::undefined,uuid,not_a_scalar,plain_object,not_a_ciphertext,no_testing,not_a_record,reserved_field,null,no_field,engine_result,outcomeandbuild_value. Some codes had several messages, and each now has one:recipher::no_field: "the record declares no sealed field of that name", for a field that is missing, passed through or not named by a string.recipher::not_a_record: "the value is not a record".recipher::outcome: "the engine returned no result".recipher::build_value: "the result could not be given to JavaScript". It no longer shows the Node-API status.recipher::value: "the value cannot be encrypted: it is not one the engine reads". It no longer copies the text of the frame error, which comes from another library.recipher::reserved_fieldno longer names the field in its message.error.fieldnames it.Ciphertext.fromBytes, or a stored row'sciphertext) now carries the engine's structured fields for that error.TypeScript errors that remain
These four are raised in TypeScript because they must exist when there is no native build, or when it answers wrongly:
recipher::load: the native build did not load, or does not export its classes.recipher::binding_interface: the native build implements another interface number.recipher::native_threw: a native call threw, as napi does for a method called on something that is not its class.recipher::outcome: the native build returned something that is not an outcome, or an error of an unknown shape.Size
crate/src/(excluding*_tests.rsandmod tests)src/*.tserror.rsgrew from 254 to 362 non-test lines, because it now holds every message, help and code the SDK writes. Every file that raised an error shrank. The whole diff is 656 lines added and 898 removed, tests andnative.d.tsincluded.Verification
Run locally in the package directory, with the debug addon rebuilt:
cargo fmt --all --check: clean.cargo test --locked --all-features:recipher-js39 and 4 passed,recipher-value-napi33 and 1 passed.cargo clippy --locked --all-targets --all-features -- -D warnings: clean. Also clean without--all-features.napi build ... --features testing --dts native.d.ts --no-const-enum:native.d.tsregenerated and committed.tsup: built.vitest run: 29 passed.vitest run --config vitest.addon.config.ts: 76 passed.tsc --noEmit -p tsconfig.json: clean.biome check languages/typescript/packages/recipher-js: clean.vitest run --config scripts/vitest.config.mjs: 96 files, 1,598 passed, 29 skipped.Not run: the release build, and anything on Linux or Windows. CI covers those.
Review notes
kindloses. No single code expresses a group. A caller who asked "is this a credential problem?" checkedkind === 'credential'. That kind coveredstack_encrypt::configand everystack_kmsauthentication code. Now the caller lists the codes. The same is true ofzerokms,open,valueandinternal. I did not add a field to replace the groups. Every distinction a test made is still made by a code: a context mismatch and a foreign keyset, both refused before any key is requested, have the engine's codesstack_encrypt::context_mismatchandstack_encrypt::foreign_keyset.recipher::reserved_keywas kindvaluewhen encrypting and kindopenwhen decrypting. The code is the same both ways, so only the call that failed says which.Refusal. Two codes appear in both, with nearly the same meaning:recipher::not_bytes(bytes given toCiphertext.fromBytes, and a typed array the bridge refuses) andrecipher::too_deep(a JSON document past 127 levels, and a value past the bridge's 128).recipher::outcomeis used by the addon ("no result") and by the TypeScript ("not an outcome"). All three are bugs or near-synonyms, so I kept them.recipher::unknownstays in the conversion as the code of a diagnostic with none. No error the addon converts lacks a code, so a caller never sees it.fieldof a field-name refusal is still the engine's payload field, as before.docs/plans/2026-11-22-recipher-typescript-sdk.mdis not changed here.Related
RecipherErrorre-describes the engine's errors with akindand string-literal codes — make it the diagnostic and nothing else #1800 (this issue), refactor(recipher-js): the value bridge says which rule a refused value broke #1805 (the base), feat(recipher-js): an error keeps the engine's help, URL, fields and causes #1791 (the error carries the whole diagnostic),recipher-jsreview cleanups: remove theLabelboundary check, deriveOpaqueDebugonRecordPlan, and rewrite the doc comments in plain language #1803 (next: review cleanups).