Use this file to discover all available pages before exploring further.
BaseApp.runTx() function handles Go panics that might occur during transaction execution, for example, when a keeper has faced an invalid state and panicked.
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 can be found in the corresponding ADR-022 and the implementation in recovery.go.
Let’s assume we want to emit the “Consensus failure” chain state if some particular error occurred.We have a module keeper that panics:
func (k FooKeeper)Do(obj interface{}) { if obj == nil { // that shouldn't happen, we need to crash the app err := errorsmod.Wrap(fooTypes.InternalError, "obj is nil")panic(err)}}
By default that panic would be recovered and an error message will be printed to log. To override that behavior we should register a custom RecoveryHandler:
// Cosmos SDK application constructor customHandler := func(recoveryObj interface{})error { err, ok := recoveryObj.(error) if !ok { return nil} if fooTypes.InternalError.Is(err) { panic(fmt.Errorf("FooKeeper did panic with error: %w", err))}return nil} baseApp := baseapp.NewBaseApp(...)baseApp.AddRunTxRecoveryHandler(customHandler)