Skip to content

RecipherError re-describes the engine's errors with a kind and string-literal codes — make it the diagnostic and nothing else #1800

Done

Description

@coderdan

Background

@cipherstash/recipher is the TypeScript SDK on the Stack Encrypt engine (the Rust crate stack-encrypt, which encrypts and decrypts values). Its Rust half is at languages/typescript/packages/recipher-js: the Node addon recipher-js (crate/) and the value bridge recipher-value-napi (value-napi/), which reads JavaScript values into the engine's value model and builds them back.

The engine's errors are miette diagnostics: each has a stable code (such as stack_encrypt::aead), a message, and often help, structured fields and causes. The SDK hands an error to the caller as a RecipherError value.

Problem

The addon describes errors a second time, in three places.

  1. ErrorKind and kind_of (crate/src/error.rs). The addon defines nine "kinds" of its own (credential, zerokms, open and so on) and a match that sorts every engine error variant into one. A new engine variant falls into internal unless someone remembers to add it. The code already says what the error is, more exactly.
  2. The same nine kinds, listed again in TypeScript (KINDS in src/error.ts), to check what the native build returned.
  3. The SDK's own errors are string literals. The addon gives 39 errors a code of its own by writing "recipher::not_a_row" and a message at each place one is raised. Nothing but a source-scanning test ties them together.

Every language SDK will meet the same choice, so the answer here is the pattern for the others: do not re-describe what the engine's diagnostic already says.

Proposal

  1. Remove kind. Delete ErrorKind, kind_of and KINDS. A RecipherError is the diagnostic and nothing else: code, message, help, url, severity, fields, causes, and field and record where the SDK names them. A caller switches on code.
  2. Make the SDK's own errors a Rust enum that derives miette::Diagnostic, with the code, message and help on each variant, as the engine does. Raise an error by naming a variant.
  3. Convert in one place. One function turns any diagnostic (the engine's, the value bridge's, the SDK's own) into the object JavaScript receives.
  4. Replace the source-scanning test with one that builds every variant and checks its code, as packages/stack-encrypt/src/codes.rs does.
  5. Update the README, the plan (docs(plans): the TypeScript SDK on Stack Encrypt, a core with EQL as an extension #1747) and the tests that assert on kind.

This is a breaking change to the package's API. The package is private and unreleased, so it needs no changeset.

Relationship to other work

Activity

  1. added
    enhancement
    on Nov 24, 2026
  2. self-assigned this
    on Nov 24, 2026
  3. added 2 commits that reference this issue on Nov 24, 2026
    872ff2e
    35213da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

SDKenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions