libsql-client: Report batch statement index on error#329
Merged
Conversation
d7214f2 to
89f4db4
Compare
If a batch statement fails, the SQL over HTTP protocol does report back exactly what step failed. However, we also need to propagate that information to the caller.
89f4db4 to
df00ade
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new LibsqlBatchError exception class that extends LibsqlError to provide better error information during batch operations. The error includes a statementIndex property that indicates which statement in the batch failed.
- Adds
LibsqlBatchErrorclass withstatementIndexproperty to track which statement in a batch operation failed - Updates error handling in batch operations across sqlite3, hrana, http, and ws implementations to wrap errors in
LibsqlBatchError - Adds comprehensive test coverage for the new error type across different scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/libsql-core/src/api.ts | Defines the new LibsqlBatchError class extending LibsqlError with a statementIndex property |
| packages/libsql-client/src/sqlite3.ts | Updates batch() methods in Sqlite3Client and Sqlite3Transaction, and migrate() to throw LibsqlBatchError with statement index when errors occur |
| packages/libsql-client/src/hrana.ts | Updates HranaTransaction.batch() and executeHranaBatch() to wrap errors in LibsqlBatchError with proper statement index tracking |
| packages/libsql-client/src/tests/client.test.ts | Adds comprehensive test cases verifying that LibsqlBatchError correctly reports statement indices in various batch failure scenarios |
Comments suppressed due to low confidence (1)
packages/libsql-client/src/hrana.ts:172
- The outer catch block will catch
LibsqlBatchErrorexceptions thrown from the inner error handling and incorrectly remap them usingmapHranaError(e). This will convert theLibsqlBatchError(which contains thestatementIndex) back into a plainLibsqlError, losing the statement index information.
To fix this, the outer catch should check if the error is already a LibsqlBatchError and rethrow it without remapping:
} catch (e) {
if (e instanceof LibsqlBatchError) {
throw e;
}
throw mapHranaError(e);
} } catch (e) {
throw mapHranaError(e);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
If a batch statement fails, the SQL over HTTP protocol does report back exactly what step failed. However, we also need to propagate that information to the caller.