Rolling back a transaction without an error
See original GitHub issueI’m using transacting
with knex and I want to rollback the transaction during normal execution. But whenever transaction.rollback()
is called it throws an unhandled exception. Providing a custom error object and trying to catch it doesn’t help since it is inside a callback.
Is there a way to rollback a transaction without throwing an error? Or is there a way to handle that error without littering the output?
Sample code:
// some previous inserts using `trans` done by now
db('actions')
.transacting(trans)
.select()
.where('id', data)
.then(function(rows) {
// do some stuff with rows
// we don't need the data anymore and want to roll back the transaction
trans.rollback();
});
Issue Analytics
- State:
- Created 9 years ago
- Comments:17 (9 by maintainers)
Top Results From Across the Web
SQL Server - transactions roll back on error? - Stack Overflow
When a connection times out, the underlying network protocol (e. g. Named Pipes or TCP ) breaks the connection. When a connection is...
Read more >How to rollback using explicit SQL Server transactions
In this article, we discussed implicit and explicit SQL Server transactions. We can decide to commit or rollback a transaction in explicit mode....
Read more >ROLLBACK TRANSACTION (Transact-SQL) - SQL Server
Error Handling. A ROLLBACK TRANSACTION statement does not produce any messages to the user. If warnings are needed in stored procedures or ...
Read more >SQL Server - Rollback Transaction Completely In Case Of Error
I recently found an issue while inserting data into a table during transactions that transaction will not completely roll back if we use ......
Read more >Rollback Transaction On Error In SQL Server Stored Procedure
In any transaction scenario, we have to rollback transaction on error in SQL execution. Using TRY-CATCH we can capture the exception occurred in ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s actually really hard to get unit tests with rollback working. I expected this to work:
What i actually had to do was …
Prevent connection pooling
Raw transaction in tests
@rapodaca rolling back changes like that is really limited way to do testing and prevent you from testing many real world use-cases. Of course some specific cases that approach is legit. Just for your information and anyone else checking this issue out 😃