-
Notifications
You must be signed in to change notification settings - Fork 469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
originalError
undefined in some transaction errors
#1716
Comments
After some debugging and looking into this library's code I realized that rolling back the transaction after an error has been thrown by sql server throws another error. So I had to change my code from this: try {
// some code
} catch (e) {
await transaction.rollback();
console.log(e);
throw e
} To this: try {
// some code
} catch (e) {
try {
await transaction.rollback();
} catch (err) {
console.error("transaction rollback", err);
}
console.log(e);
throw e;
} I wasn't aware that rolling back a transaction would throw another error. Is this intended behavior? If so, it is not totally clear that it is the case by reading the documentation.
And the fact that it's aborted makes it throw the error? Also, is there a better pattern for this? Seems to me that having to handle two errors is too much code spaguettization. I'm wondering if I'm just not using the library the way it was intended. The only reason I have to catch and re-throw is to rollback the transaction. Edit: I leave it to the authors to close this issue, the only reason I kept it open is to see if I can get some feedback on this particular issue and confirm this is expected behavior. |
Thanks for posting the issue and digging into what is going on. I think what is happening is that There is an option that can be set against the tedious driver ( |
I do not set abortTransactionOnError in my config and I just just checked in the database: Also we recently fixed our application hanging due to transactions staying open after an error (never commiting or rolling back). Which is actually why I catch, rollback and re-throw. Looks like the tedious default for I also ruled out an error originating from the application because after making the changes where I catch the I guess my next step would be to debug and inspect the state of the transactions and what's causing |
I'm currently working through the error log of our service and noticing that some errors during transactions don't have the
originalError
property and others do:Example of correct error:
Expected behaviour:
Original error property to exist in the error to verify the underlying problem with the query.
For example, this is an error that originated due to a failed constraint:
Actual behaviour:
There are other errors in which the
originalError
property doesn't exists:Configuration:
Software versions
Why is this error not being instantiated correctly? or is this error originating from within the application?
The text was updated successfully, but these errors were encountered: