tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.48k stars 913 forks source link

No stack trace when panic happens in WASM #4444

Closed mymmrac closed 2 months ago

mymmrac commented 2 months ago

TinyGo v0.32.0

Simple example:

package main

func main() {
    panic("test")
}

When compiled with regular Go (GOOS=js GOARCH=wasm) and run in browser console looks like this:

panic: test
<empty string>
goroutine 1 [running]:
main.main()
    /<path-to-file>/main.go:4 +0x2

But when compiled with TinyGo (-target wasm) it looks like this:

panic: test

How to get full stack trace of panic when using TinyGo?

aykevl commented 2 months ago

TinyGo does not include this information, to reduce binary file size. If you want stack traces, the VM needs to support them. Apparently the browser you're using doesn't. But wasmtime does, if you set the WASMTIME_BACKTRACE_DETAILS=1 environment variable.

mymmrac commented 2 months ago

So TinyGo uses something different then Go for panic stack trace? Because in both cases I used Firefox and Go wasm binary printed full stack trace

dgryski commented 2 months ago

@mymmrac Yes. TinyGo and Go handle panics and stack traces differently.

mymmrac commented 2 months ago

Got it, many thanks for the information and quick reply

Just in case someone encounters similar issues, using Chrome you can get a kind of stack trace, but it will link to wasm code (in WAT format), but still it can help identify the issue