@@ -134,16 +134,28 @@ export abstract class HranaTransaction implements Transaction {
134134 }
135135
136136 const resultSets = [ ] ;
137- for ( const rowsPromise of rowsPromises ) {
138- const rows = await rowsPromise ;
139- if ( rows === undefined ) {
140- throw new LibsqlError (
141- "Statement in a transaction was not executed, " +
142- "probably because the transaction has been rolled back" ,
143- "TRANSACTION_CLOSED" ,
144- ) ;
137+ for ( let i = 0 ; i < rowsPromises . length ; i ++ ) {
138+ try {
139+ const rows = await rowsPromises [ i ] ;
140+ if ( rows === undefined ) {
141+ throw new LibsqlError (
142+ `Statement at index ${ i } in a transaction was not executed, ` +
143+ "probably because the transaction has been rolled back" ,
144+ "TRANSACTION_CLOSED" ,
145+ ) ;
146+ }
147+ resultSets . push ( resultSetFromHrana ( rows ) ) ;
148+ } catch ( e ) {
149+ if ( e instanceof LibsqlError ) {
150+ throw new LibsqlError (
151+ `Statement at index ${ i } failed: ${ e . message } ` ,
152+ e . code ,
153+ e . rawCode ,
154+ e . cause ,
155+ ) ;
156+ }
157+ throw e ;
145158 }
146- resultSets . push ( resultSetFromHrana ( rows ) ) ;
147159 }
148160 return resultSets ;
149161 } catch ( e ) {
@@ -295,15 +307,27 @@ export async function executeHranaBatch(
295307
296308 const resultSets = [ ] ;
297309 await beginPromise ;
298- for ( const stmtPromise of stmtPromises ) {
299- const hranaRows = await stmtPromise ;
300- if ( hranaRows === undefined ) {
301- throw new LibsqlError (
302- "Statement in a batch was not executed, probably because the transaction has been rolled back" ,
303- "TRANSACTION_CLOSED" ,
304- ) ;
310+ for ( let i = 0 ; i < stmtPromises . length ; i ++ ) {
311+ try {
312+ const hranaRows = await stmtPromises [ i ] ;
313+ if ( hranaRows === undefined ) {
314+ throw new LibsqlError (
315+ `Statement at index ${ i } in a batch was not executed, probably because the transaction has been rolled back` ,
316+ "TRANSACTION_CLOSED" ,
317+ ) ;
318+ }
319+ resultSets . push ( resultSetFromHrana ( hranaRows ) ) ;
320+ } catch ( e ) {
321+ if ( e instanceof LibsqlError ) {
322+ throw new LibsqlError (
323+ `Statement at index ${ i } failed: ${ e . message } ` ,
324+ e . code ,
325+ e . rawCode ,
326+ e . cause ,
327+ ) ;
328+ }
329+ throw e ;
305330 }
306- resultSets . push ( resultSetFromHrana ( hranaRows ) ) ;
307331 }
308332 await commitPromise ;
309333
0 commit comments