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

Better error messages #1669

Open
andig opened this issue Nov 23, 2024 · 0 comments
Open

Better error messages #1669

andig opened this issue Nov 23, 2024 · 0 comments

Comments

@andig
Copy link

andig commented Nov 23, 2024

Proposal

Accessing an unimported stdlib package panics instead of returning an error:

if _, err := vm.Eval("var ts time.Time"); err != nil {
	return err
}

Gives

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x128 pc=0x105598e6c]

goroutine 24 [running]:
testing.tRunner.func1.2({0x105f655e0, 0x106a7c4e0})
	/opt/homebrew/Cellar/go/1.23.3/libexec/src/testing/testing.go:1632 +0x1bc
testing.tRunner.func1()
	/opt/homebrew/Cellar/go/1.23.3/libexec/src/testing/testing.go:1635 +0x334
panic({0x105f655e0?, 0x106a7c4e0?})
	/opt/homebrew/Cellar/go/1.23.3/libexec/src/runtime/panic.go:785 +0x124
github.com/traefik/yaegi/interp.isComplete(0x140001f78c8?, 0x1400059a090?)
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/type.go:1415 +0x1c
github.com/traefik/yaegi/interp.(*itype).isComplete(...)
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/type.go:1412
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0x14000824f00)
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/gta.go:121 +0x174c
github.com/traefik/yaegi/interp.(*node).Walk(0x14000824f00, 0x1400085d778, 0x0)
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/interp.go:282 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0x14000824dc0, 0x1400085d778, 0x0)
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/interp.go:286 +0x74
github.com/traefik/yaegi/interp.(*node).Walk(0x14000824b40, 0x1400085d778, 0x0)
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/interp.go:286 +0x74
github.com/traefik/yaegi/interp.(*Interpreter).gta(0x140001f78c8, 0x14000824b40, {0x1400078d710, 0x4}, {0x1400078d710, 0x4}, {0x1400078d710, 0x4})
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/gta.go:20 +0x158
github.com/traefik/yaegi/interp.(*Interpreter).gtaRetry(0x140001f78c8, {0x1400085d970?, 0x14000342fa0?, 0x1400085d8a8?}, {0x1400078d710, 0x4}, {0x1400078d710, 0x4})
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/gta.go:395 +0x118
github.com/traefik/yaegi/interp.(*Interpreter).CompileAST(0x140001f78c8, {0x1060f5a60?, 0x14000342fa0?})
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/program.go:92 +0xec
github.com/traefik/yaegi/interp.(*Interpreter).compileSrc(0x140001f78c8, {0x105b94171?, 0xffffffffffffffff?}, {0x0?, 0x1400085d8e8?}, 0x90?)
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/program.go:64 +0xb8
github.com/traefik/yaegi/interp.(*Interpreter).eval(0x140001f78c8, {0x105b94171?, 0x0?}, {0x0?, 0x0?}, 0x0?)
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/interp.go:554 +0x28
github.com/traefik/yaegi/interp.(*Interpreter).Eval(...)
	/Users/andig/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/interp.go:496

Background

The NPE is hard to reason about. It would be nice to have a better error message indicating which nil object is being accessed or where in the code this happens.

Workarounds

Recover the panic and extract the stack trace to even find out where the error comes from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant