Agent skill
go-nil-interface
Interface nil trap - typed nil is not nil
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/development/go-nil-interface
SKILL.md
Interface Nil Trap
Problem
A typed nil pointer stored in an interface is NOT nil.
Pattern
WRONG - Typed nil escapes
func GetUser(id int) error {
var err *MyError // typed nil
if id < 0 {
err = &MyError{"invalid id"}
}
return err // Returns non-nil interface containing nil pointer!
}
if err := GetUser(1); err != nil {
// This branch RUNS even though no error occurred
fmt.Println("error:", err)
}
CORRECT - Return untyped nil
func GetUser(id int) error {
if id < 0 {
return &MyError{"invalid id"}
}
return nil // Return untyped nil
}
if err := GetUser(1); err != nil {
// This branch does NOT run
fmt.Println("error:", err)
}
Why It Happens
Interface contains (type, value). Typed nil has (type=*MyError, value=nil). This is different from (type=nil, value=nil).
Quick Fix
- Return nil directly, not typed nil variable
- Or return concrete type, not interface
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?