-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: confusing stack trace in case of deferring <nil> function #15466
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
Comments
Thanks for your error report. Can you please tell us the version of Go you On Wed, 27 Apr 2016, 19:15 Alexey Nezhdanov, notifications@github.com
|
The play.golang.org (used to create this thread) reports version "go1.6.2". |
Thank you. I've confirmed that with 093ac15 the backtrace message also On Wed, Apr 27, 2016 at 8:58 PM, Alexey Nezhdanov notifications@github.com
|
Deferring a nil function pointer produces a stack trace that does not mention the deferred function. This could be quite time-consuming to debug in case of, say, this use case:
cancel, err := Open(ctx)
if err!=nil {
log.Error(err)
// note that I forgot to put 'return' in here
}
defer cancel()
// many lines of code here
return nil
The snippet above will generate a panic() pointing to the 'return nil' line as the last line of user code.
Perhaps the error message could be improved.
Example: https://play.golang.org/p/jx3SBaSNlt
Current stack trace:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0xffffffff addr=0x0 pc=0x93074]
goroutine 1 [running]:
panic(0x13f3e0, 0x1040a038)
/usr/local/go/src/runtime/panic.go:481 +0x700
main.a(0xfef70018, 0x1040a120)
/tmp/sandbox234618258/main.go:11 +0xfb
main.main()
/tmp/sandbox234618258/main.go:15 +0x20
The text was updated successfully, but these errors were encountered: