Skip to content
Back to skills

Checking

ASecurity

Type-safe error inspection using errors.Is and errors.As

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

Security analysis

A100/100

Scanned February 12, 2026

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

Installs into .claude/skills of the current project.

Are you the author of Checking?

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

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

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-error-checking
description: Type-safe error inspection using errors.Is and errors.As
---

# Error Checking

## Pattern
Use `errors.Is` to check sentinel errors and `errors.As` to extract error types.

## errors.Is - Check Sentinel Errors
```go
// CORRECT
if errors.Is(err, user.ErrNotFound) {
    return http.StatusNotFound
}

// WRONG - breaks with wrapped errors
if err == user.ErrNotFound { }
```

## errors.As - Extract Error Types
```go
// CORRECT - extracts specific error type
var pathErr *fs.PathError
if errors.As(err, &pathErr) {
    log.Printf("failed path: %s", pathErr.Path)
    log.Printf("operation: %s", pathErr.Op)
}

// WRONG - only checks direct type
if pathErr, ok := err.(*fs.PathError); ok { }
```

## Complete Example
```go
func HandleError(err error) {
    // Check sentinel errors
    if errors.Is(err, user.ErrNotFound) {
        fmt.Println("User not found")
        return
    }

    // Extract custom error types
    var validationErr *ValidationError
    if errors.As(err, &validationErr) {
        fmt.Printf("Validation failed: %v\n", validationErr.Fields)
        return
    }

    // Extract standard library errors
    var pathErr *fs.PathError
    if errors.As(err, &pathErr) {
        fmt.Printf("File operation failed: %s\n", pathErr.Path)
        return
    }

    // Generic error
    fmt.Printf("Unknown error: %v\n", err)
}
```

## Key Differences
- `errors.Is`: Checks if error matches a sentinel value (works through wrapping)
- `errors.As`: Extracts error of specific type (works through wrapping)
- Never use `==` or type assertions for wrapped errors

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.

Comments

Loading comments…

Newsletter

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