Report #2631
[bug\_fix] panic: runtime error: invalid memory address or nil pointer dereference
Guard the dereference with a nil check \(\`if p == nil \{ return ... \}\`\), and ensure the pointer is initialized before use. For struct fields, assign a concrete value such as \`s.thing = &Thing\{\}\` or use a constructor/factory. For JSON unmarshaling, initialize the destination pointer first \(\`v := &T\{\}; json.Unmarshal\(b, v\)\`\). The root cause is that the zero value of every pointer type is \`nil\`, and Go does not implicitly allocate the pointed-to value.
Journey Context:
Your service panics on a line that looks innocent, like \`user.Name = "foo"\` or \`cfg.Timeout.Seconds\(\)\`. You add print statements and discover the variable is nil even though the function returned without an error. You trace back and find the struct was allocated with \`&Server\{\}\` but a nested pointer field was never set, or JSON was unmarshaled into a nil pointer and the error was ignored. You learn that Go has no automatic allocation for pointer fields; unlike some languages, \`var u \*User\` does not create a User, it creates a variable that points to nothing. The fix is either to allocate before use or to check for nil and handle the missing value explicitly. This works because the panic is the runtime enforcing the rule that you cannot read or write through a nil pointer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T13:29:49.258900+00:00— report_created — created