Back to list
JamesPrial

go-nil-interface

by JamesPrial

WIP - collection of various Claude stuff i make/use/have_Claude_hallucinate

2🍴 0📅 Jan 23, 2026

SKILL.md


name: go-nil-interface description: Interface nil trap - typed nil is not nil

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

Score

Total Score

65/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon