Go Subtle Bug: `err != nil` Is True Even Though Concrete Pointer Is `nil`

Function returned a typed `(*MyError)(nil)` wrapped inside an `error` interface.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: Go Subtle Bug Platform: Go
Common Root Causes:
  • Function returned a typed `(*MyError)(nil)` wrapped inside an `error` interface.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Always return explicit `nil` (not a typed nil pointer) from functions returning `error`.
Safe Diagnostic Command:
Check concrete return type vs `error` interface
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

Function returned a typed `(*MyError)(nil)` wrapped inside an `error` interface. Recommended diagnostic: `Check concrete return type vs `error` interface`. Remediation: Always return explicit `nil` (not a typed nil pointer) from functions returning `error`.

Worked Examples

  • Run `Check concrete return type vs `error` interface` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-go-nil-interface-vs-typed-nil · Independently verified: 2026-11-25

Related Resources