Skip to content

Conversation

@penberg
Copy link
Contributor

@penberg penberg commented Nov 1, 2025

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.

@penberg penberg force-pushed the batch-errors branch 2 times, most recently from d7214f2 to 89f4db4 Compare November 10, 2025 10:18
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.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 LibsqlBatchError class with statementIndex property 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 LibsqlBatchError exceptions thrown from the inner error handling and incorrectly remap them using mapHranaError(e). This will convert the LibsqlBatchError (which contains the statementIndex) back into a plain LibsqlError, 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.

@penberg penberg merged commit da3cb0a into main Nov 10, 2025
12 checks passed
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