When a user calls the CLI on a Cosmos chain and it panics, the impact depends on where the panic occurs. This document outlines the different scenarios and their respective impacts.
If the panic happens in the CLI client code (before sending to the chain):
- Only affects the user's local CLI process
- No impact on the blockchain or other users
- Transaction is never submitted to the chain
- CLI process crashes and exits
$ mychain tx bank send ...
panic: runtime error: nil pointer dereference
# CLI crashes, nothing sent to chainIf the CLI successfully submits a transaction that causes a panic during execution:
- Transaction fails and is rejected
- Gas is consumed up to the panic point
- No state changes are committed
- Chain continues operating normally
- Error is returned to the user
// Cosmos SDK has panic recovery in BaseApp
defer func() {
if r := recover(); r != nil {
// Log the panic
// Return error response
// Continue chain operation
}
}()- Entire blockchain halts
- All validators stop producing blocks
- Network becomes unavailable
- Requires manual intervention/upgrade
If a CLI query command triggers a panic:
- Query fails and returns error
- No state changes (queries are read-only)
- Chain continues normally
- Only affects that specific query
// BaseApp wraps execution with recovery
func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, result *sdk.Result, err error) {
defer func() {
if r := recover(); r != nil {
err = handlePanic(r)
}
}()
// ... transaction execution
}- Prevent infinite loops that could cause resource exhaustion
- Force transactions to complete within gas bounds
- Validate transactions before execution
- Catch common issues early
// Always validate inputs
if msg.Amount.IsNil() {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "amount cannot be nil")
}// Use safe operations
if balance.IsZero() {
return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient balance")
}// Handle edge cases
if len(msg.Recipients) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "no recipients specified")
}| Scenario | Impact Level | Description |
|---|---|---|
| CLI Panic | Low | Local issue only - affects single user |
| Transaction Panic | Medium | Transaction fails, chain continues |
| Block Processing Panic | Critical | Chain halts completely |
- Cosmos SDK has built-in panic recovery for most scenarios
- Proper validation and error handling prevent most panic situations
- Client-side panics have minimal impact
- Chain-side panics during block processing are the most serious concern