Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Go Errors

ASecurity

Enforces Go error handling — errors as values, wrapping with %w, errors.Is and errors.As over type assertions, sentinel and custom error types, and when panic is acceptable. Use when writing, reviewing, or debugging Go error paths, and when the user mentions err != nil, error wrapping, errors.Is, errors.As, sentinel errors, panic, recover, errors.Join, or asks "how should I return this error", "why is errors.Is failing", "should this panic".

2 stars
0 votes
0 copies
0 views
Added 9/19/2026
developmentgosqldebuggingapi

Works with

api

Security Analysis

A100/100

Scanned 9/19/2026

$npx -y skills add CasLubbers/code-design-skills --skill go-errors --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Go Errors?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Go Errors
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/caslubbers-go-errors/badge)](https://www.skillsdirectory.com/skills/caslubbers-go-errors)

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

Download with Pro
Files
SKILL.md
---
name: go-errors
description: Enforces Go error handling — errors as values, wrapping with %w, errors.Is and errors.As over type assertions, sentinel and custom error types, and when panic is acceptable. Use when writing, reviewing, or debugging Go error paths, and when the user mentions err != nil, error wrapping, errors.Is, errors.As, sentinel errors, panic, recover, errors.Join, or asks "how should I return this error", "why is errors.Is failing", "should this panic".
---

# Go errors

Errors are ordinary values. There is no exception mechanism to fall back on, so the error path is designed, not discovered.

## Wrap with context, keep the chain

Every layer adds what it was doing. `%w` preserves the original for inspection.

```go
// Good — reads as a path once printed: "load user: query user 42: sql: no rows in result set"
if err := rows.Scan(&u.ID, &u.Name); err != nil {
    return nil, fmt.Errorf("query user %s: %w", id, err)
}

// Bad — chain broken, errors.Is downstream stops working
return nil, fmt.Errorf("query user: %v", err)

// Bad — no context, caller cannot tell which of six calls failed
return nil, err
```

Wrap when you add information. Returning `err` unchanged is correct when the callee's message already says everything.

## Error strings are lowercase and unpunctuated

They get embedded in other messages.

```go
errors.New("connection refused")     // good
errors.New("Connection refused.")    // bad — reads wrong once wrapped
```

Do not start with the word "error" or "failed to" — the context makes that obvious.

## Inspect with errors.Is and errors.As

Never compare with `==` on a wrapped error, and never type-assert directly.

```go
// Sentinel — a known condition callers branch on
var ErrNotFound = errors.New("not found")

if errors.Is(err, ErrNotFound) {
    return http.StatusNotFound
}

// Typed — the caller needs data out of the error
type ValidationError struct {
    Field  string
    Reason string
}

func (e *ValidationError) Error() string {
    return fmt.Sprintf("invalid %s: %s", e.Field, e.Reason)
}

var ve *ValidationError
if errors.As(err, &ve) {
    log.Printf("field %s rejected", ve.Field)
}
```

Choose a sentinel when callers only need to know *which* condition. Choose a type when they need details. Export either only if callers genuinely branch on it — an exported sentinel is part of your API forever.

## Unwrap for custom types

A custom error that carries a cause must expose it, or `errors.Is` cannot see through it.

```go
type QueryError struct {
    Query string
    Err   error
}

func (e *QueryError) Error() string { return e.Query + ": " + e.Err.Error() }
func (e *QueryError) Unwrap() error { return e.Err }
```

## Combining errors

`errors.Join` collects several failures where you must not stop at the first — validating a whole form, closing several resources.

```go
var errs error
for _, f := range fields {
    errs = errors.Join(errs, f.Validate())
}
return errs
```

`errors.Is` matches against any error in a joined set.

## Never discard silently

```go
// Bad
result, _ := doWork()

// Fine — the discard is deliberate and explained
_ = resp.Body.Close() // best effort; response already read
```

In `defer`, a failing `Close` on a *writer* can lose data. Capture it:

```go
defer func() {
    if cerr := f.Close(); cerr != nil && err == nil {
        err = fmt.Errorf("close: %w", cerr)
    }
}()
```

That requires a named return: `func write() (err error)`.

## panic is for programmer error only

Panic when the program cannot sensibly continue — an impossible switch branch, a failed invariant, a `MustCompile` at init with a literal pattern. Never panic across a package boundary for anything a caller could have caused: bad input, a missing file, a network failure. Those are returned errors.

A library that panics on user input is a broken library. If you must recover, do it at a process boundary (an HTTP middleware) and convert to an error there.

## Where to log

Log where you handle, not where you return. Logging *and* returning produces the same failure printed five times at five layers. The top of the call stack decides what the user sees.

Attribution

CasLubbersCasLubbers
View sourceSee grades on GitHubMore from CasLubbers →
SSkills Directory ProSkills Directory

Get any skill into Claude in one click.

Download any skill as a ZIP for Claude.ai, Claude Desktop, or .claude/skills. $9/mo.

See Pro

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 (0)

No comments yet. Be the first to comment!

SSkills Directory ProSkills Directory

Get any skill into Claude in one click.

Download any skill as a ZIP for Claude.ai, Claude Desktop, or .claude/skills. $9/mo.

See Pro

Related Skills

Clean Code

Pragmatic coding standards - concise, direct, no over-engineering, no unnecessary comments

304955 votes

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

285172 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2222 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

10311 votes
View all in development →