Skip to content

chore(stack): upgrade @byteslice/result 0.2 → 0.5#582

Draft
coderdan wants to merge 1 commit into
mainfrom
chore/byteslice-result-0.5
Draft

chore(stack): upgrade @byteslice/result 0.2 → 0.5#582
coderdan wants to merge 1 commit into
mainfrom
chore/byteslice-result-0.5

Conversation

@coderdan

@coderdan coderdan commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What

Upgrade @cipherstash/stack's @byteslice/result dependency from 0.2.0 → 0.5.0, resolving the breaking change to the Result failure model. Follows on from #568 (auth 0.41, now merged, already ships 0.5's Result).

Why

@byteslice/result 0.5's FailureOption no longer accepts a bare { type: string } shape — a failure must be an Error or carry an error: Error. Stack's EncryptionError ({ type; message; code? }) satisfied 0.2 but not 0.5, so every Result<…, EncryptionError> usage broke (78 type errors across 15 files). This unblocks the tracked byteslice alignment and removes a version skew with auth 0.41.

How

  • EncryptionError gains a required error: Error holding the originating error. type / message / code are unchanged, so any code reading result.failure.type / .message / .code keeps working — additive for consumers.
  • New toEncryptionError(type, error, code?) factory coerces any caught value to a real Error (replacing the pre-existing unchecked (error as Error) idiom — a small correctness win) and derives the message.
  • All 27 hand-built failure literals across encryption/* + identity/ now route through the factory. tsc-driven, mechanical.

Verification

  • tsc --noEmit clean, tsup build clean, biome check clean.
  • Offline suites pass: validation, wasm-inline-strategy, cjs-require.
  • Remaining suite failures are the pre-existing live-integration tests that need local CipherStash credentials (Client key not configured) — 0 assertion failures, so nothing the refactor touched regressed.

Scope

  • Scoped to packages/stack. packages/protect is deprecated, so its @byteslice/result pin is intentionally left untouched.
  • Only the base EncryptionError (which flows through Result) gained error; the StackError member interfaces are unchanged.

https://claude.ai/code/session_01RRUEHiYupwGo6eEWTBhRaj

0.5's `FailureOption` no longer accepts a bare `{ type }` shape — a failure
must be an `Error` or carry an `error: Error`. This aligns stack with
`@cipherstash/auth` 0.41 (which already ships 0.5's Result) and unblocks the
tracked byteslice migration.

- `EncryptionError` gains a required `error: Error` holding the originating
  error; `type` / `message` / `code` are unchanged, so readers of
  `result.failure.*` are unaffected.
- New `toEncryptionError(type, error, code?)` factory coerces any caught value
  to a real `Error` (never an unchecked `as Error`) and derives the message;
  all 27 hand-built failure literals across encryption/* + identity now route
  through it.

Verified: `tsc` clean, `tsup` build clean, biome clean. Offline suites
(validation, wasm-inline strategy, cjs-require) pass; remaining suite failures
are the pre-existing live-integration tests that need local CipherStash creds.
@coderdan coderdan requested a review from a team as a code owner July 8, 2026 08:36
@changeset-bot

changeset-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 19331ac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@cipherstash/stack Minor
@cipherstash/bench Patch
@cipherstash/prisma-next Patch
@cipherstash/basic-example Patch
@cipherstash/prisma-next-example Patch
@cipherstash/e2e Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@coderdan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 30 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1dca9bfc-49e6-4102-b3ca-921c3c77353a

📥 Commits

Reviewing files that changed from the base of the PR and between 7dba25d and 19331ac.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (16)
  • .changeset/byteslice-result-0-5.md
  • packages/stack/package.json
  • packages/stack/src/encryption/helpers/validation.ts
  • packages/stack/src/encryption/index.ts
  • packages/stack/src/encryption/operations/batch-encrypt-query.ts
  • packages/stack/src/encryption/operations/bulk-decrypt-models.ts
  • packages/stack/src/encryption/operations/bulk-decrypt.ts
  • packages/stack/src/encryption/operations/bulk-encrypt-models.ts
  • packages/stack/src/encryption/operations/bulk-encrypt.ts
  • packages/stack/src/encryption/operations/decrypt-model.ts
  • packages/stack/src/encryption/operations/decrypt.ts
  • packages/stack/src/encryption/operations/encrypt-model.ts
  • packages/stack/src/encryption/operations/encrypt-query.ts
  • packages/stack/src/encryption/operations/encrypt.ts
  • packages/stack/src/errors/index.ts
  • packages/stack/src/identity/index.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/byteslice-result-0.5

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Upgrade @cipherstash/stack to @byteslice/result@0.5.0 by updating the EncryptionError failure shape to satisfy the new FailureOption requirements, and mechanically refactoring stack operations/identity flows to construct failures via a shared factory.

Changes:

  • Bump @byteslice/result from 0.2.00.5.0 (package + lockfile).
  • Add error: Error to EncryptionError and introduce toEncryptionError(type, error, code?) to safely coerce unknown thrown values.
  • Route operation/identity failure mapping through toEncryptionError and add a Changeset for the minor release.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pnpm-lock.yaml Locks @byteslice/result@0.5.0 for packages/stack.
packages/stack/package.json Updates stack’s direct dependency pin to 0.5.0.
packages/stack/src/errors/index.ts Updates EncryptionError contract and adds toEncryptionError factory.
packages/stack/src/identity/index.ts Migrates CTS-token failure mapping to toEncryptionError.
packages/stack/src/encryption/index.ts Migrates client-init failure mapping to toEncryptionError.
packages/stack/src/encryption/helpers/validation.ts Updates validation failure results to include a real Error via the factory.
packages/stack/src/encryption/operations/encrypt.ts Migrates encryption failure mapping to toEncryptionError.
packages/stack/src/encryption/operations/decrypt.ts Migrates decryption failure mapping to toEncryptionError.
packages/stack/src/encryption/operations/encrypt-query.ts Migrates encryptQuery failure mapping to toEncryptionError.
packages/stack/src/encryption/operations/encrypt-model.ts Migrates encryptModel failure mapping to toEncryptionError.
packages/stack/src/encryption/operations/decrypt-model.ts Migrates decryptModel failure mapping to toEncryptionError.
packages/stack/src/encryption/operations/bulk-encrypt.ts Migrates bulkEncrypt failure mapping to toEncryptionError.
packages/stack/src/encryption/operations/bulk-decrypt.ts Migrates bulkDecrypt failure mapping to toEncryptionError.
packages/stack/src/encryption/operations/bulk-encrypt-models.ts Migrates bulkEncryptModels failure mapping to toEncryptionError.
packages/stack/src/encryption/operations/bulk-decrypt-models.ts Migrates bulkDecryptModels failure mapping to toEncryptionError.
packages/stack/src/encryption/operations/batch-encrypt-query.ts Migrates batch encryptQuery failure mapping to toEncryptionError.
.changeset/byteslice-result-0-5.md Declares a minor release for the dependency + failure-shape change.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +123 to +127

/**
* Build an {@link EncryptionError} from a caught value.
*
* `@byteslice/result` 0.5 requires a failure to be an `Error` or to carry an
Comment on lines +138 to +142
const err = error instanceof Error ? error : new Error(getErrorMessage(error))
return code === undefined
? { type, message: err.message, error: err }
: { type, message: err.message, code, error: err }
}
@coderdan coderdan marked this pull request as draft July 8, 2026 11:41
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.

2 participants