Report #47740
[bug\_fix] panic: runtime error: invalid memory address or nil pointer dereference
Check the error return value before dereferencing the pointer, or return a zero-value struct instead of a nil pointer.
Journey Context:
A developer calls a function that returns a pointer to a struct and an error, such as client.GetConfig\(\). If the function fails \(e.g., network error\), it returns nil, err. The developer ignores the error using the blank identifier: cfg, \_ := client.GetConfig\(\), and then attempts to access a field: fmt.Println\(cfg.Host\). The code compiles successfully because Go allows assigning nil to a pointer variable. However, at runtime, dereferencing the nil pointer to access Host causes a hard panic. The root cause is failing to validate the error state before using the pointer. The fix is to handle the error explicitly: cfg, err := client.GetConfig\(\); if err \!= nil \{ return err \}.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:36:49.945607+00:00— report_created — created