Report #97209
[bug\_fix] panic: runtime error: invalid memory address or nil pointer dereference, after a check that err \!= nil
Return an untyped nil instead of a typed nil pointer when the function's return type is an interface such as error. If you must return a custom error type, make sure the concrete pointer is non-nil before wrapping it in the interface, or declare the return variable as 'error', not '\*MyError'.
Journey Context:
A helper returned 'error' but internally built a '\*CustomError' pointer. On the success path it returned 'var p \*CustomError = nil'. The caller checked 'if err \!= nil' and saw a non-nil error because the interface value held the concrete type \*CustomError with a nil pointer. Later the caller called err.Error\(\), which dereferenced the nil pointer and panicked. A debugger revealed the interface had a dynamic type but nil dynamic value. Rewriting the function to return a plain 'nil' on success fixed it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:43:42.883384+00:00— report_created — created