Skip to content

Commit

Permalink
Stop returning error logs + stack trace when out of gas in ApplyFuncI…
Browse files Browse the repository at this point in the history
…fNoErr (backport #2914) (#2917)

* Stop returning error logs + stack trace when out of gas in ApplyFuncIfNoErr (#2914)

* Stop returning error logs + stack trace when
theres an out of gas in ApplyFuncIfNoErr

* Fix import

* Changelog

(cherry picked from commit 1ec8658)

# Conflicts:
#	CHANGELOG.md
#	osmoutils/cache_ctx.go

* add gitiginore and changelog

* merge conflict fix

Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>
  • Loading branch information
3 people authored Oct 13, 2022
1 parent feab082 commit 1adb561
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
33 changes: 32 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,36 @@ $RECYCLE.BIN/
/.idea/
/artifacts/
/.vscode/
/.VSCodeCounter/
/scripts/local/
/x/incentives/keeper/osmosis_testing/
/x/incentives/keeper/osmosis_testing/
tools-stamp
/tests/localosmosis/.osmosisd/*
*.save
*.save.*

mutation_test_result.txt
go_mutation_test_result.txt

# Rust ignores. Generated by Cargo
# will have compiled files and executables
debug/
target/

# Generated by rust-optimizer
artifacts/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Ignores beaker state
.beaker
blocks.db
**/blocks.db*
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

* [2261](https://github.com/osmosis-labs/osmosis/pull/2261) feat: speedup epoch distribution, superfluid component (backport #2214)
* [#2914](https://github.com/osmosis-labs/osmosis/pull/2914) Remove out of gas panics from node logs

## [v7.3.0](https://github.com/osmosis-labs/osmosis/releases/tag/v7.3.0)

Expand Down
32 changes: 29 additions & 3 deletions osmoutils/cache_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package osmoutils
import (
"errors"
"fmt"
"runtime"
"runtime/debug"

"github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -14,9 +17,9 @@ import (
func ApplyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) (err error) {
// Add a panic safeguard
defer func() {
if recovErr := recover(); recovErr != nil {
fmt.Println(recovErr)
err = errors.New("panic occured during execution")
if recoveryError := recover(); recoveryError != nil {
PrintPanicRecoveryError(ctx, recoveryError)
err = errors.New("panic occurred during execution")
}
}()
// makes a new cache context, which all state changes get wrapped inside of.
Expand All @@ -30,3 +33,26 @@ func ApplyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) (err err
}
return err
}

// PrintPanicRecoveryError error logs the recoveryError, along with the stacktrace, if it can be parsed.
// If not emits them to stdout.
func PrintPanicRecoveryError(ctx sdk.Context, recoveryError interface{}) {
errStackTrace := string(debug.Stack())
switch e := recoveryError.(type) {
case types.ErrorOutOfGas:
ctx.Logger().Debug("out of gas error inside panic recovery block: " + e.Descriptor)
return
case string:
ctx.Logger().Error("Recovering from (string) panic: " + e)
case runtime.Error:
ctx.Logger().Error("recovered (runtime.Error) panic: " + e.Error())
case error:
ctx.Logger().Error("recovered (error) panic: " + e.Error())
default:
ctx.Logger().Error("recovered (default) panic. Could not capture logs in ctx, see stdout")
fmt.Println("Recovering from panic ", recoveryError)
debug.PrintStack()
return
}
ctx.Logger().Error("stack trace: " + errStackTrace)
}

0 comments on commit 1adb561

Please sign in to comment.