gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + gno.land: a blockchain for timeless code and fair open-source.
https://gno.land/
Other
900 stars 379 forks source link

[GnoVM] Better error message with `MsgRun` #2562

Open leohhhn opened 4 months ago

leohhhn commented 4 months ago

Description

MsgRun is meant to only support package main func main() {} Gno code.

When you try to execute package mypackage that contains a main() function, the below error happens:

--= Error =--
Data: internal error
Msg Traces:
    0  /Users/sasurai/Desktop/gno/gno/tm2/pkg/crypto/keys/client/maketx.go:213 - deliver transaction failed: log:recovered: runtime error: index out of range [-1]
stack:
goroutine 82 [running]:
runtime/debug.Stack()
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/runtime/debug/stack.go:24 +0x64
github.com/gnolang/gno/tm2/pkg/sdk.(*BaseApp).runTx.func1()
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/sdk/baseapp.go:743 +0x1a0
panic({0x10158c100?, 0x1400e033ba8?})
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/runtime/panic.go:770 +0x124
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).LastBlock(...)
        /Users/sasurai/Desktop/gno/gno/gnovm/pkg/gnolang/machine.go:1750
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).String(0x140134a6b48)
        /Users/sasurai/Desktop/gno/gno/gnovm/pkg/gnolang/machine.go:2158 +0x1900
github.com/gnolang/gno/gno.land/pkg/sdk/vm.(*VMKeeper).Run.func1()
        /Users/sasurai/Desktop/gno/gno/gno.land/pkg/sdk/vm/keeper.go:526 +0xa8
panic({0x101455c20?, 0x14012ce13d0?})
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/runtime/panic.go:770 +0x124
github.com/gnolang/gno/gnovm/pkg/gnolang.ParseMemPackage(0x140110f2c80)
        /Users/sasurai/Desktop/gno/gno/gnovm/pkg/gnolang/nodes.go:1198 +0x2a8
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).runMemPackage(0x140134a6b48, 0x140110f2c80, 0x0, 0x0)
        /Users/sasurai/Desktop/gno/gno/gnovm/pkg/gnolang/machine.go:268 +0x34
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).RunMemPackage(...)
        /Users/sasurai/Desktop/gno/gno/gnovm/pkg/gnolang/machine.go:255
github.com/gnolang/gno/gno.land/pkg/sdk/vm.(*VMKeeper).Run(_, {{0x101621938, 0x140117e2cc0}, 0x1, {0x101620ad0, 0x14010ff2bb0}, {0x101621c80, 0x1400bab6dc0}, {0x14005311c2b, 0x3}, ...}, ...)
        /Users/sasurai/Desktop/gno/gno/gno.land/pkg/sdk/vm/keeper.go:532 +0x874
github.com/gnolang/gno/gno.land/pkg/sdk/vm.vmHandler.handleMsgRun({_}, {{0x101621938, 0x140117e2cc0}, 0x1, {0x101620ad0, 0x14010ff2bb0}, {0x101621c80, 0x1400bab6dc0}, {0x14005311c2b, 0x3}, ...}, ...)
        /Users/sasurai/Desktop/gno/gno/gno.land/pkg/sdk/vm/handler.go:63 +0x8c
github.com/gnolang/gno/gno.land/pkg/sdk/vm.vmHandler.Process({0x12b8af308?}, {{0x101621938, 0x140117e2cc0}, 0x1, {0x101620ad0, 0x14010ff2bb0}, {0x101621c80, 0x1400bab6dc0}, {0x14005311c2b, 0x3}, ...}, ...)
        /Users/sasurai/Desktop/gno/gno/gno.land/pkg/sdk/vm/handler.go:35 +0x1f8
github.com/gnolang/gno/tm2/pkg/sdk.(*BaseApp).runMsgs(0x140000c2400, {{0x101621938, 0x140117e2cc0}, 0x1, {0x101620ad0, 0x14010ff2bb0}, {0x101621c80, 0x1400bab6dc0}, {0x14005311c2b, 0x3}, ...}, ...)
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/sdk/baseapp.go:646 +0x21c
github.com/gnolang/gno/tm2/pkg/sdk.(*BaseApp).runTx(0x140000c2400, 0x1, {0x140004d2000?, 0x14017674f90?, 0x14000050318?}, {{0x14010adfee0, 0x1, 0x1}, {0x1312d00, {{0x140053c3027, ...}, ...}}, ...})
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/sdk/baseapp.go:823 +0x808
github.com/gnolang/gno/tm2/pkg/sdk.(*BaseApp).Simulate(...)
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/sdk/helpers.go:17
github.com/gnolang/gno/tm2/pkg/sdk.handleQueryApp(0x140000c2400, {0x1401116e2a0?, 0x0?, 0x0?}, {{}, {0x140004d2000, 0x4da8, 0x4da9}, {0x140053c2fb0, 0xd}, ...})
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/sdk/baseapp.go:410 +0x20c
github.com/gnolang/gno/tm2/pkg/sdk.(*BaseApp).Query(0x140000c2400, {{}, {0x140004d2000, 0x4da8, 0x4da9}, {0x140053c2fb0, 0xd}, 0x0, 0x0})
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/sdk/baseapp.go:383 +0x10c
github.com/gnolang/gno/tm2/pkg/bft/abci/client.(*localClient).QuerySync(0x1401764a8d8?, {{}, {0x140004d2000, 0x4da8, 0x4da9}, {0x140053c2fb0, 0xd}, 0x0, 0x0})
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/bft/abci/client/local_client.go:180 +0x118
github.com/gnolang/gno/tm2/pkg/bft/appconn.(*query).QuerySync(0x1401764aa68?, {{}, {0x140004d2000, 0x4da8, 0x4da9}, {0x140053c2fb0, 0xd}, 0x0, 0x0})
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/bft/appconn/app_conn.go:144 +0x98
github.com/gnolang/gno/tm2/pkg/bft/rpc/core.ABCIQuery(0x140112e63c0?, {0x140053c2fb0, 0xd}, {0x140004d2000, 0x4da8, 0x4da9}, 0x0?, 0x3?)
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/bft/rpc/core/abci.go:59 +0xc8
reflect.Value.call({0x1014e0ec0?, 0x10160e558?, 0x1401764b3d8?}, {0x10107ebee, 0x4}, {0x140134c9e80, 0x5, 0x100f74cfc?})
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/reflect/value.go:596 +0x970
reflect.Value.Call({0x1014e0ec0?, 0x10160e558?, 0x67c9?}, {0x140134c9e80?, 0x101609d40?, 0x1000?})
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/reflect/value.go:380 +0x94
github.com/gnolang/gno/tm2/pkg/bft/rpc/lib/server.RegisterRPCFuncs.makeJSONRPCHandler.func9({0x101620950, 0x14011160990}, 0x1401767e7e0)
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/bft/rpc/lib/server/handlers.go:185 +0x620
github.com/gnolang/gno/tm2/pkg/bft/rpc/lib/server.RegisterRPCFuncs.handleInvalidJSONRPCPaths.func10({0x101620950?, 0x14011160990?}, 0x1400f51a8d8?)
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/bft/rpc/lib/server/handlers.go:209 +0x5c
net/http.HandlerFunc.ServeHTTP(0x1400d4a61a0?, {0x101620950?, 0x14011160990?}, 0x1006ec28c?)
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/net/http/server.go:2166 +0x38
net/http.(*ServeMux).ServeHTTP(0x1400d4a6410?, {0x101620950, 0x14011160990}, 0x1401767e7e0)
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/net/http/server.go:2683 +0x1a4
github.com/gnolang/gno/tm2/pkg/bft/node.(*Node).startRPC.(*Cors).Handler.func5({0x101620950, 0x14011160990}, 0x1401767e7e0)
        /Users/sasurai/go/pkg/mod/github.com/rs/cors@v1.11.0/cors.go:289 +0x19c
net/http.HandlerFunc.ServeHTTP(0x0?, {0x101620950?, 0x14011160990?}, 0x100b29b3c?)
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/net/http/server.go:2166 +0x38
github.com/gnolang/gno/tm2/pkg/bft/rpc/lib/server.maxBytesHandler.ServeHTTP({{0x101616c60?, 0x14010475420?}, 0x8?}, {0x101620950, 0x14011160990}, 0x1401767e7e0)
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/bft/rpc/lib/server/http_server.go:216 +0xec
github.com/gnolang/gno/tm2/pkg/bft/rpc/lib/server.StartHTTPServer.RecoverAndLogHandler.func1({0x10161f7b0, 0x140176569a0}, 0x1401767e7e0)
        /Users/sasurai/Desktop/gno/gno/tm2/pkg/bft/rpc/lib/server/http_server.go:189 +0x190
net/http.HandlerFunc.ServeHTTP(0x10?, {0x10161f7b0?, 0x140176569a0?}, 0x140176569a0?)
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/net/http/server.go:2166 +0x38
net/http.serverHandler.ServeHTTP({0x10161c690?}, {0x10161f7b0?, 0x140176569a0?}, 0x6?)
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/net/http/server.go:3137 +0xbc
net/http.(*conn).serve(0x14017650900, {0x101621938, 0x1401653c0f0})
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/net/http/server.go:2039 +0x508
created by net/http.(*Server).Serve in goroutine 12
        /Users/sasurai/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/net/http/server.go:3285 +0x3f0

--= /Error =--

While in the case of having a package main without a main() function, the following error shows up:

--= Error =--
Data: gno.land/r/g125em6arxsnj49vx35f0n0z34putv5ty3376fg5/run/:0:0: name main not declared:
--- preprocess stack ---
thinhnx-var commented 4 months ago

Do you mean that when we try to run a package xxx with a main() inside, the error should be clearer like ~main() should be in main package~ MsgRun should be executed in main package ? I think this is better than the stack traces are printed out.