Report #103412
[bug\_fix] runtime error: invalid memory address or nil pointer dereference
Add an explicit nil check before dereferencing the pointer, or ensure the value is initialized before use. If the pointer comes from a constructor/factory, return an error instead of nil on failure so callers cannot dereference a nil result.
Journey Context:
A service panics in production with \`runtime error: invalid memory address or nil pointer dereference\`. The stack trace points to a method call on a struct pointer. Locally the test passes because the test always initializes the struct. The developer adds logging and finds that an upstream function returns nil when a config file is missing but does not return an error. They patch the immediate line with \`if x == nil \{ return err \}\`, then refactor the constructor to return \`\(T, error\)\` instead of \`\*T\` so nil cannot silently escape. The fix works because Go does not guard pointer dereferences at compile time; the only safe pattern is validating initialization at the boundary where the pointer is produced.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-11T04:21:15.780767+00:00— report_created — created