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

examples: basic tinygo example fails with tinygo 0.35.0 #2357

Open
mauriciovasquezbernal opened this issue Jan 7, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@mauriciovasquezbernal
Copy link

mauriciovasquezbernal commented Jan 7, 2025

Describe the bug
Running the basic example when compiled with tinygo v0.35.0 fails.

To Reproduce

  1. Compile the example with tinygo v0.35.0
$ tinygo version
tinygo version 0.35.0 linux/amd64 (using go version go1.23.4 and LLVM version 18.1.8)

$ tinygo build -o add.wasm -target=wasi add.go
  1. Run the example
$ go run . 5 8
2025/01/07 15:10:25 failed to call add: module closed with exit_code(0)
panic: failed to call add: module closed with exit_code(0)

goroutine 1 [running]:
log.Panicf({0x69ad7b?, 0x6f2e30?}, {0xc000587f28?, 0xc0003b3270?, 0x1bb41?})
        /usr/local/go/src/log/log.go:439 +0x65
main.main()
        /home/mauriciov/kinvolk/ebpf/wazero/examples/basic/add.go:60 +0x2f9
exit status 2

Expected behavior

Example should run fine.

Environment (please complete the relevant information):

  • Go version: 1.23.4
  • wazero Version: 610c202
  • Host architecture: amd64
  • Runtime mode: -

Additional context

It's a duplicated of #2352 which was closed because "It's not a bug - see the error message saying your module exited with zero.". If it's not a bug, then the sample code on this repository should be updated. I tried using ExitError, but now it crashes in another place:

diff --git a/examples/basic/add.go b/examples/basic/add.go
index 93658e9a..a4eedd70 100644
--- a/examples/basic/add.go
+++ b/examples/basic/add.go
@@ -11,6 +11,7 @@ import (

        "github.com/tetratelabs/wazero"
        "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
+       "github.com/tetratelabs/wazero/sys"
 )

 // addWasm was generated by the following:
@@ -57,9 +58,15 @@ func main() {
        add := mod.ExportedFunction("add")
        results, err := add.Call(ctx, x, y)
        if err != nil {
-               log.Panicf("failed to call add: %v", err)
+               if exitErr, ok := err.(*sys.ExitError); ok && exitErr.ExitCode() == 0 {
+                       // Exited with code 0. Nothing to worry about.
+               } else {
+                       log.Panicf("failed to call add: %v", err)
+               }
        }

+       fmt.Printf("results is %v\n", results)
+
        fmt.Printf("%d + %d = %d\n", x, y, results[0])
 }
$ go run . 5 8
results is []
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.main()
        /home/mauriciov/kinvolk/ebpf/wazero/examples/basic/add.go:70 +0x478
exit status 2

I bisected tinygo and it happens from tinygo-org/tinygo@ceb7891 if that's relevant somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant