Report #741
[bug\_fix] nil pointer dereference from a method with a nil receiver returning a non-nil interface
Return the concrete \`\*MyError\` \(or nil concrete pointer\) directly instead of converting a nil concrete pointer into an interface value. Interfaces are only nil when both type and value are nil; a typed nil pointer stored in an interface is non-nil.
Journey Context:
A service kept panicking with 'runtime error: invalid memory address or nil pointer dereference' on a line where I checked \`err \!= nil\` and it passed. I attached a debugger and saw that \`err\` was indeed a non-nil interface wrapping a nil \`\*MyError\`. The bug was in an error helper: it returned \`error\(nilPointer\)\` where \`nilPointer\` was a \`\*MyError\` that happened to be nil. Because Go interfaces store a type descriptor plus a value, the interface itself was non-nil even though the concrete pointer inside was nil. I changed the helper to return the concrete pointer directly \(so a nil \`\*MyError\` produces a nil interface\) and added a test asserting \`err == nil\` for the success path. The panic disappeared and the error-handling path became predictable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T12:52:33.130548+00:00— report_created — created