Skip to content

Commit 5efb805

Browse files
committed
TR-1863: If an error occurs during _rollback_ of a transaction, make sure to capture the original error that caused the rollback as well.
1 parent d1d0791 commit 5efb805

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Sources/SQLite/Core/Connection.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,24 @@ public final class Connection {
356356

357357
try transaction(savepoint, block, "RELEASE \(savepoint)", or: "ROLLBACK TO \(savepoint)")
358358
}
359+
360+
fileprivate struct ErrorDuringRollback: Error {
361+
let originalError: Error
362+
let rollbackError: Error
363+
}
359364

360365
fileprivate func transaction(_ begin: String, _ block: () throws -> Void, _ commit: String, or rollback: String) throws {
361366
return try sync {
362367
try self.run(begin)
363368
do {
364-
try block()
369+
try block()
365370
try self.run(commit)
366371
} catch {
367-
try self.run(rollback)
372+
do {
373+
try self.run(rollback)
374+
} catch let rollbackError {
375+
throw ErrorDuringRollback(originalError: error, rollbackError: rollbackError)
376+
}
368377
throw error
369378
}
370379
}

0 commit comments

Comments
 (0)