smithery/JamesPrial

go-nil-interface

Interface nil trap - typed nil is not nil

Installation

$ npx skills add smithery/JamesPrial --skill go-nil-interface

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery/JamesPrial · top by installs.

npx skills add smithery/JamesPrial

Browse all from smithery/JamesPrial

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 1,069 B
  • docs SUMMARY.md 65 B

History

  1. First recorded snapshot · 0 installs

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