A CATCH block rolls back without checking that a transaction is open

tx0/sql:unguarded-rollbackrecommendedwarningreliability/resourcesdepth fastbug

What it finds

ROLLBACK in a CATCH block fails with "no corresponding BEGIN TRANSACTION" when the error happened before the transaction began or after it ended, and that second error replaces the first. IF @@TRANCOUNT > 0 ROLLBACK or XACT_STATE() guards it.

From the rule's source, unguarded_rollback.rs.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/sql:unguarded-rollback" = "warning"

To keep one finding, suppress it with a reason: tx0 suppress ID --reason "..." writes the comment for it.

tx0 explain tx0/sql:unguarded-rollback shows the same in the terminal. Found a false positive? Report it.