Skip to content
Back to skills

Interface

ASecurity

Interface nil trap - typed nil is not nil

  • 3 stars
  • 0 votes
  • 0 copies
  • 17 views
  • Added February 7, 2026
developmentgo

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add JamesPrial/claudefiles --skill interface --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Interface?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Interface
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jamesprial-interface/badge)](https://www.skillsdirectory.com/skills/jamesprial-interface)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
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
```go
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
```go
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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.