Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve error response structure and metadata #3845

Merged
merged 2 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions gno.land/pkg/integration/testdata/err_metadata.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ensure users get proper out of gas errors when they add packages

# start a new node
gnoland start

! gnokey maketx addpkg -pkgdir $WORK/invalid -pkgpath gno.land/r/invalid -gas-fee 1000000ugnot -gas-wanted 60000 -broadcast -chainid=tendermint_test test1

stdout 'TX HASH:'
stdout 'INFO:.*vm.version=develop'
stderr '--= Error =--'
stderr 'Data: invalid gno package; type check errors:'
stderr 'gno.land/r/invalid/invalid.gno:.*:.*: expected operand, found .EOF.'
stderr 'Msg Traces:'
stderr ' 0 .*gno/tm2/pkg/errors/errors.go:.* - deliver transaction failed: log:msg:0,success:false,log:--= Error =--'
stderr 'Data: vm.TypeCheckError{abciError:vm.abciError{}, Errors:..string{"gno.land/r/invalid/invalid.gno:.*:.*: expected operand, found .EOF."}}'
stderr 'Msg Traces:'
stderr 'Stack Trace:'
stderr ' 0 .*gno.land/pkg/sdk/vm/errors.go:.*'
#...
stderr '--= /Error =--'
stderr ',events:..'
stderr '--= /Error =--'

-- invalid/invalid.gno --
package invalid
var Foo =
5 changes: 4 additions & 1 deletion gno.land/pkg/sdk/vm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/gnolang/gno/gnovm/pkg/version"
abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
"github.com/gnolang/gno/tm2/pkg/sdk"
"github.com/gnolang/gno/tm2/pkg/std"
Expand Down Expand Up @@ -187,7 +188,9 @@ func (vh vmHandler) queryFile(ctx sdk.Context, req abci.RequestQuery) (res abci.
// misc

func abciResult(err error) sdk.Result {
return sdk.ABCIResultFromError(err)
res := sdk.ABCIResultFromError(err)
res.Info += "vm.version=" + version.Version
return res
}

// returns the second component of a path.
Expand Down
2 changes: 2 additions & 0 deletions tm2/pkg/crypto/keys/client/maketx.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
}
if bres.DeliverTx.IsErr() {
io.Println("TX HASH: ", base64.StdEncoding.EncodeToString(bres.Hash))
io.Println("INFO: ", bres.DeliverTx.Info)

Check warning on line 215 in tm2/pkg/crypto/keys/client/maketx.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/maketx.go#L215

Added line #L215 was not covered by tests
return errors.Wrapf(bres.DeliverTx.Error, "deliver transaction failed: log:%s", bres.DeliverTx.Log)
}

Expand All @@ -221,6 +222,7 @@
io.Println("GAS USED: ", bres.DeliverTx.GasUsed)
io.Println("HEIGHT: ", bres.Height)
io.Println("EVENTS: ", string(bres.DeliverTx.EncodeEvents()))
io.Println("INFO: ", bres.DeliverTx.Info)

Check warning on line 225 in tm2/pkg/crypto/keys/client/maketx.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/maketx.go#L225

Added line #L225 was not covered by tests
io.Println("TX HASH: ", base64.StdEncoding.EncodeToString(bres.Hash))

return nil
Expand Down
3 changes: 3 additions & 0 deletions tm2/pkg/sdk/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res
ctx = ctx.WithEventLogger(NewEventLogger())

msgLogs := make([]string, 0, len(msgs))
msgInfos := make([]string, 0, len(msgs))
data := make([]byte, 0, len(msgs))

var (
Expand Down Expand Up @@ -675,6 +676,7 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res
// each result.
data = append(data, msgResult.Data...)
events = append(events, msgResult.Events...)
msgInfos = append(msgInfos, msgResult.Info)

// stop execution and return on first failed message
if !msgResult.IsOK() {
Expand All @@ -698,6 +700,7 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res
result.Error = ABCIError(err)
result.Data = data
result.Events = events
result.Info = strings.Join(msgInfos, "\n")
result.Log = strings.Join(msgLogs, "\n")
result.GasUsed = ctx.GasMeter().GasConsumed()
return result
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/sdk/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (app *BaseApp) SetDB(db dbm.DB) {

func (app *BaseApp) SetCMS(cms store.CommitMultiStore) {
if app.sealed {
panic("SetEndBlocker() on sealed BaseApp")
panic("SetCMS() on sealed BaseApp")
}
app.cms = cms
}
Expand Down
Loading