Agent skill

Golang Error Handling

by unxed in unxed/f4

Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog…

MITAuto-check passedDevOps & Cloud

Install Golang Error Handling

skills CLI
$ npx skills add unxed/f4 --skill golang-error-handling -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install unxed/f4 golang-error-handling --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/unxed/f4.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/golang-error-handling .claude/skills/golang-error-handling && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
golang-error-handling
GitHub stars
243
Used in
3 other repos
Token cost
~1.8k tokens
SKILL.md length
720 words
Files
5 (incl. references)
Skills in repo
36
Repo updated
First seen
Licence
MIT

At a glance

Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog…

  • Works in 12 steps: Returned errors MUST always be checked —… → Errors MUST be wrapped with context… → Error strings MUST be lowercase, without… → …
  • Tasks that involve Observability
  • SKILL.md covers Best Practices Summary, Detailed Reference, Parallelizing Error Handling… and Cross-References, plus 1 more section
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Golang Error Handling is an agent skill from unxed/f4. Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog, HTTP request logging middleware, and samber/oops for production errors. Built to make logs usable at scale with log aggregation 3rd-party tools. Apply when creating, wrapping, inspecting, or logging errors in Go code. For samber/oops specifics → See samber/cc-skills-golang@golang-samber-oops skill; for slog handler…

Its SKILL.md is about 1.8k tokens, which your agent loads only when the skill is triggered. The skill folder holds 6 other files, including reference files (for example `evals/evals.json`, `references/error-creation.md` and `references/error-handling.md`). Compatibility notes: Designed for Claude Code, Codex or similar harness, and for projects using Golang.

It sits in DevOps & Cloud, covering Observability and Error handling. It works with Go. The repository describes itself as: dual pane like a charm. The licence is MIT.

When your agent uses it

  • Tasks that involve Observability
  • Tasks that involve Error handling

Example prompts

  • “/golang-error-handling”

Requirements

  • Compatibility (from SKILL.md): Designed for Claude Code, Codex or similar harness, and for projects using Golang.
  • Pre-approved tools (allowed-tools): Read, Edit, Write, Glob, Grep, Bash(go:*), Bash(golangci-lint:*), Bash(git:*), Agent

Workflow steps

12 steps, taken from the first numbered list in SKILL.md.

  1. Returned errors MUST always be checked — NEVER discard with _
  2. Errors MUST be wrapped with context using fmt.Errorf("{context}: %w", err)
  3. Error strings MUST be lowercase, without trailing punctuation
  4. Use %w internally, %v at system boundaries to control error chain exposure
  5. MUST use errors.Is for sentinel matching and errors.As/errors.AsType for typed chain inspection instead of direct comparison or bare type…
  6. SHOULD use errors.Join (Go 1.20+) to combine independent errors
  7. Errors MUST be either logged OR returned, NEVER both (single handling rule)
  8. Use sentinel errors for expected conditions, custom types for carrying data
  9. NEVER use panic for expected error conditions — reserve for truly unrecoverable states
  10. SHOULD use slog (Go 1.21+) for structured error logging — not fmt.Println or log.Printf
  11. Use samber/oops for production errors needing stack traces, user/tenant context, or structured attributes
  12. Log HTTP requests with structured middleware capturing method, path, status, and duration

What it can do on your machine

Read from SKILL.md and the folder at commit 772edc7. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Edit
    • Write
    • Glob
    • Grep
    • Bash(go:*)
    • Bash(golangci-lint:*)
    • Bash(git:*)
    • Agent

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • github.com
    • pkg.go.dev

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Designed for Claude Code, Codex or similar harness, and for projects using Golang.

    From compatibility in the SKILL.md frontmatter.

Context cost

Golang Error Handling loads about 1.8k tokens when it runs, and up to ~5.4k if it reads all its reference files. Until then it costs about 151 tokens; SKILL.md has 720 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~151
When it runs · the whole SKILL.md, loaded when a task matches
~1.8k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~5.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from unxed/f4 at commit 772edc7, republished under its MIT licence (© unxed). 720 words, ~1,828 tokens.

Download SKILL.mdSave it as .claude/skills/golang-error-handling/SKILL.md (or your agent's skills folder). This skill also uses 4 other files; get the full folder from GitHub.
name
golang-error-handling
description
Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog, HTTP request logging middleware, and samber/oops for production errors. Built to make logs usable at scale with log aggregation 3rd-party tools. Apply when creating, wrapping, inspecting, or logging errors in Go code. For samber/oops specifics → See `samber/cc-skills-golang@golang-samber-oops` skill; for slog handler ecosystem → See `samber/cc-skills-golang@golang-samber-slog` skill.
allowed-tools
Read, Edit, Write, Glob, Grep, Bash(go:*), Bash(golangci-lint:*), Bash(git:*), Agent
compatibility
Designed for Claude Code, Codex or similar harness, and for projects using Golang.
user-invocable
true
license
MIT
metadata.author
samber
metadata.version
1.3.1
paths
**/*.go

Persona: You are a Go reliability engineer. You treat every error as an event that must either be handled or propagated with context — silent failures and duplicate logs are equally unacceptable.

Orchestration mode: Fan out the five category sub-agents described in the "Parallelizing Error Handling Audits" section (creation, wrapping, single-handling rule, panic/recover, structured logging) for auditing error handling across a large codebase, and consolidate their findings. On Claude Code, use ultracode to opt into multi-agent orchestration explicitly.

Modes:

  • Coding mode — writing new error handling code. Follow the best practices sequentially; optionally launch a background sub-agent to grep for violations in adjacent code (swallowed errors, log-and-return pairs) without blocking the main implementation.
  • Review mode — reviewing a PR's error handling changes. Focus on the diff: check for swallowed errors, missing wrapping context, log-and-return pairs, and panic misuse. Sequential.
  • Audit mode — auditing existing error handling across a codebase. Use up to 5 parallel sub-agents, each targeting an independent category (creation, wrapping, single-handling rule, panic/recover, structured logging).

Community default. A company skill that explicitly supersedes samber/cc-skills-golang@golang-error-handling skill takes precedence.

Go Error Handling Best Practices

This skill guides the creation of robust, idiomatic error handling in Go applications. Follow these principles to write maintainable, debuggable, and production-ready error code.

Best Practices Summary

  1. Returned errors MUST always be checked — NEVER discard with _
  2. Errors MUST be wrapped with context using fmt.Errorf("{context}: %w", err)
  3. Error strings MUST be lowercase, without trailing punctuation
  4. Use %w internally, %v at system boundaries to control error chain exposure
  5. MUST use errors.Is for sentinel matching and errors.As/errors.AsType for typed chain inspection instead of direct comparison or bare type assertions. For Go 1.26+, prefer errors.AsType[T](err) when T implements error; use errors.As(err, &target) for Go <1.26 or for non-error interface targets.
  6. SHOULD use errors.Join (Go 1.20+) to combine independent errors
  7. Errors MUST be either logged OR returned, NEVER both (single handling rule)
  8. Use sentinel errors for expected conditions, custom types for carrying data
  9. NEVER use panic for expected error conditions — reserve for truly unrecoverable states
  10. SHOULD use slog (Go 1.21+) for structured error logging — not fmt.Println or log.Printf
  11. Use samber/oops for production errors needing stack traces, user/tenant context, or structured attributes
  12. Log HTTP requests with structured middleware capturing method, path, status, and duration
  13. Use log levels to indicate error severity
  14. Never expose technical errors to users — translate internal errors to user-friendly messages, log technical details separately
  15. Keep log grouping low-cardinality — at logging/APM boundaries, keep message templates stable and attach IDs, paths, line numbers, and counts as structured attributes. Error values may include useful operational context, but avoid putting high-cardinality data into the stable log message used for grouping.
Show full SKILL.md (272 more words)Show less

Detailed Reference

  • Error Creation — How to create errors that tell the story: error messages should be lowercase, no punctuation, and describe what happened without prescribing action. Covers sentinel errors (one-time preallocation for performance), custom error types (for carrying rich context), and the decision table for which to use when.

  • Error Wrapping and Inspection — Why fmt.Errorf("{context}: %w", err) beats fmt.Errorf("{context}: %v", err) (chains vs concatenation). How to inspect chains with errors.Is, errors.As, and Go 1.26+ errors.AsType for type-safe error handling, and errors.Join for combining independent errors.

  • Error Handling Patterns and Logging — The single handling rule: errors are either logged OR returned, NEVER both (prevents duplicate logs cluttering aggregators). Panic/recover design, samber/oops for production errors, and slog structured logging integration for APM tools.

Parallelizing Error Handling Audits

When auditing error handling across a large codebase, use up to 5 parallel sub-agents — each targets an independent error category:

  • Sub-agent 1: Error creation — validate errors.New/fmt.Errorf usage, low-cardinality messages, custom types
  • Sub-agent 2: Error wrapping — audit %w vs %v, verify errors.Is/errors.As patterns
  • Sub-agent 3: Single handling rule — find log-and-return violations, swallowed errors, discarded errors (_)
  • Sub-agent 4: Panic/recover — audit panic usage, verify recovery at goroutine boundaries
  • Sub-agent 5: Structured logging — verify slog usage at error sites, check for PII in error messages

Cross-References

  • → See samber/cc-skills-golang@golang-samber-oops for full samber/oops API, builder patterns, and logger integration
  • → See samber/cc-skills-golang@golang-observability for structured logging setup, log levels, and request logging middleware
  • → See samber/cc-skills-golang@golang-safety for nil interface trap and nil error comparison pitfalls
  • → See samber/cc-skills-golang@golang-naming for error naming conventions (ErrNotFound, PathError)
  • → See samber/cc-skills-golang@golang-continuous-integration skill for automated AI-driven code review in CI using these guidelines

References

© unxed, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 4 other files (references) in .agents/skills/golang-error-handling of unxed/f4.

  • SKILL.md
  • evals/evals.json
  • references/error-creation.md
  • references/error-handling.md
  • references/error-wrapping.md

Open the folder on GitHubat commit 772edc7

Used in 3 other repositories

We found 3 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 3 other GitHub owners. This page covers the copy in unxed/f4, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Golang Error Handling next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Golang Error Handling compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Golang Error Handling this skillunxed/f42433 repos~1.8kAutomated safety check: PassMIT
Logging Observabilitygetsentry/toolkit920—~2.6kAutomated safety check: PassCustom licence
fp-go Logging PatternsIBM/fp-go2k—~3.7kAutomated safety check: PassApache-2.0
Crash Instrumentationnexus-labs-automation/mobile-observability116—~744Automated safety check: PassMIT
Golang Samber Slogcontext-labs/whip1.1k2 repos~3kAutomated safety check: PassMIT
Deploy Observabilityaliyun/alibabacloud-observability-mcp-server166—~2.6kAutomated safety check: NotesNone

Similar skills

  • Logging Observability

    getsentry/toolkit

    Official

    Review code for correct logging and error handling patterns.

    920 GitHub stars~2.6k tokensUpdated yesterday
    DevOps & CloudAuto-check passed
  • Official

    Adds logging to fp-go functional pipelines with Tap operators, entry and exit logs and error context, so that logging never changes the value or error flowing through.

    2k GitHub stars~3.7k tokensUpdated today
    DevelopmentAuto-check passed
  • Crash Instrumentation

    nexus-labs-automation/mobile-observability

    Set up crash instrumentation with actionable context. An agent skill from nexus-labs-automation/mobile-observability.

    116 GitHub stars~744 tokensUpdated 1 mo ago
    DevOps & CloudAuto-check passed
  • Golang Samber Slog

    context-labs/whip

    Structured logging extensions for Golang using samber/slog- — multi-handler pipelines, sampling, attribute formatting, HTTP middleware (gin, echo, fiber, chi), backend routing (datadog, sentry…

    1.1k GitHub starsUsed in 2 repos~3k tokens
    DevOps & CloudAuto-check passed
  • Deploy Observability

    aliyun/alibabacloud-observability-mcp-server

    Deploy, start, and update the Alibaba Cloud Observability MCP Server (阿里云可观测 MCP Server).

    166 GitHub stars~2.6k tokensUpdated 2 mo ago
    DevOps & CloudAuto-check: notes
  • Error Handler

    EliasOulkadi/shokunin

    Design error handling, structured logging, and observability with OpenTelemetry (traces, metrics, logs), error classification, recovery patterns (retry with jitter, circuit breaker, bulkhead…

    114 GitHub stars~3.6k tokensUpdated 6 days ago
    DevOps & CloudAuto-check: notes

More from unxed/f4

All 36 skills in this repo
  • Comprehensive documentation guide for Golang projects, covering godoc comments, README, CONTRIBUTING, CHANGELOG, Go Playground, Example tests, API docs, and llms.txt.

    244 GitHub starsUsed in 3 repos~3.5k tokens
    Auto-check passed
  • Golang code style conventions — line length and breaking, variable declarations, control flow clarity, when comments help vs hurt.

    244 GitHub starsUsed in 3 repos~2.5k tokens
    Auto-check passed
  • Comprehensive guide for Go database access — parameterized queries, struct scanning, NULLable columns, transactions, isolation levels, SELECT FOR UPDATE, connection pool, batch processing, context…

    244 GitHub starsUsed in 2 repos~2.9k tokens
    Auto-check passed
  • Security audit checklist based on OWASP Top 10 and best practices.

    244 GitHub stars~5.4k tokensUpdated today
    Auto-check: notes
  • Go (Golang) naming conventions — covers packages, constructors, structs, interfaces, constants, enums, errors, booleans, receivers, getters/setters, functional options, acronyms, test functions, and…

    244 GitHub starsUsed in 2 repos~3.1k tokens
    Auto-check passed
  • Golang concurrency design — goroutine lifecycle and leak prevention, channels and select, channel ownership and direction, sync.Mutex/RWMutex/sync.Map/sync.Once/atomics, errgroup, singleflight…

    244 GitHub starsUsed in 1 repo~2.4k tokens
    Auto-check passed

Works with

Questions about Golang Error Handling

What does Golang Error Handling do?

Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog…. Golang Error Handling is an agent skill from unxed/f4.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog, HTTP request logging middleware, and samber/oops for production errors.

When should I use Golang Error Handling?

Golang Error Handling fits situations like: tasks that involve Observability; tasks that involve Error handling.

How do I install Golang Error Handling in Claude Code?

Run `npx skills add unxed/f4 --skill golang-error-handling -a claude-code`. Or copy the skill folder (.agents/skills/golang-error-handling in unxed/f4) into .claude/skills/golang-error-handling in your project. Claude Code loads it when a task matches its description.

How do I install Golang Error Handling in Codex?

Run `npx skills add unxed/f4 --skill golang-error-handling -a codex`. Or copy the skill folder (.agents/skills/golang-error-handling in unxed/f4) into .agents/skills/golang-error-handling in your project. Codex loads it when a task matches its description.

Can I use Golang Error Handling in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add unxed/f4 --skill golang-error-handling -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/golang-error-handling, .gemini/skills/golang-error-handling, .github/skills/golang-error-handling and .opencode/skills/golang-error-handling in your project.

What does Golang Error Handling need to run?

SKILL.md names no scripts, command-line tools or credentials: Golang Error Handling is instructions for the agent only. Its frontmatter pre-approves these tools: Read, Edit, Write, Glob, Grep, Bash(go:*), Bash(golangci-lint:*), Bash(git:*), Agent. Compatibility (from SKILL.md): Designed for Claude Code, Codex or similar harness, and for projects using Golang..

Does Golang Error Handling access the network?

SKILL.md names 2 domains. As links in the text: github.com and pkg.go.dev. This is read from the text; nothing was executed.

Is Golang Error Handling safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Golang Error Handling use?

Golang Error Handling is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Golang Error Handling use?

About 1.8k tokens (SKILL.md is roughly 7.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 3.6k tokens, read only when the agent opens those files.

What are the alternatives to Golang Error Handling?

Skills that share tags, products or a category with Golang Error Handling: Logging Observability (getsentry/toolkit, 920 stars), fp-go Logging Patterns (IBM/fp-go, 2k stars), Crash Instrumentation (nexus-labs-automation/mobile-observability, 116 stars) and Golang Samber Slog (context-labs/whip, 1.1k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Golang Error Handling?

unxed (a GitHub user) maintains it in unxed/f4, which has 243 GitHub stars. The repository holds 36 skills in this directory. The repository was last updated on October 10, 2026.

Source: unxed/f4 on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.