# RunTx recovery middleware
BaseApp.runTx() function handles Golang panics that might occur during transactions execution, for example, keeper has faced an invalid state and paniced.
Depending on the panic type different handler is used, for instance the default one prints an error log message.
Recovery middleware is used to add custom panic recovery for Cosmos SDK application developers.
More context could be found in the corresponding ADR-022.
Implementation could be found in the recovery.go file.
recoveryObj is a return value for
recover() function from the
buildin Golang package.
- RecoveryHandler returns
recoveryObjwasn't handled and should be passed to the next recovery middleware;
- RecoveryHandler returns a non-nil
# Custom RecoveryHandler register
BaseApp method adds recovery middleware to the default recovery chain.
Lets assume we want to emit the "Consensus failure" chain state if some particular error occurred.
We have a module keeper that panics:
By default that panic would be recovered and an error message will be printed to log. To override that behaviour we should register a custom RecoveryHandler:
Learn about the IBC protocol