Skip to content

fix(rivetkit): surface native sqlite kv errors to callers#4645

Draft
NathanFlurry wants to merge 1 commit intofix/prevent-sleep-db-racesfrom
fix/surface-native-sqlite-kv-errors
Draft

fix(rivetkit): surface native sqlite kv errors to callers#4645
NathanFlurry wants to merge 1 commit intofix/prevent-sleep-db-racesfrom
fix/surface-native-sqlite-kv-errors

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 13, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude bot commented Apr 13, 2026

PR Review: fix(rivetkit): surface native sqlite kv errors to callers

Summary

This PR enriches SQLite errors propagated through the wrapJsNativeDatabase wrapper to include the underlying KV-channel error when an I/O-class SQLite failure occurs. The VFS layer cannot propagate KV errors upward through the SQLite C API, so it stores them via set_last_error/take_last_error (a destructive read). Without this fix, callers only see opaque disk I/O error messages with no root cause. The fix looks correct and well-motivated.


Issues

Medium: Missing test coverage for exec and query paths

The test file only exercises db.run(). The exec and query code paths have identical enrichNativeDatabaseError call sites but no test coverage. Also missing:

  • A test where takeLastKvError() returns null (no KV error recorded) - the error should pass through unchanged.
  • A test for the deduplication guard (!error.message.includes(kvError)).

Issues (cont)

Medium: close() errors are not enriched

If the VFS records a KV error during a flush on close, it will be silently swallowed. Worth checking whether take_last_error can fire during close, and if so, wrapping close() similarly.

Positives

  • The never return type on enrichNativeDatabaseError is correct and keeps TypeScript flow analysis clean.
  • The deduplication guard (!error.message.includes(kvError)) prevents double-appending.
  • No vi.mock/jest.mock usage. Stubs are implemented as hand-written createDatabase() overrides, consistent with CLAUDE.md testing conventions.
  • No CLAUDE.md convention violations found (no rivet.gg, no Mutex, no em dashes, no unstructured logging).

Checklist before merge

  • Add tests for exec and query error enrichment paths
  • Add test for takeLastKvError() returning null (no-op path)
  • Confirm tsc --noEmit passes (all PR checklist items are currently unchecked on this DRAFT)
  • Consider documenting the destructive-read semantics on takeLastKvError? in the interface

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