# Go error handling

> Go error handling is an open-source agent skill for developer tools. Guides an AI agent through Go error wrapping, sentinel errors and custom error types. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/eduardo-sl/go-agent-skills/tree/main/skills/(code-quality)/go-error-handling
- **Repository:** https://github.com/eduardo-sl/go-agent-skills
- **GitHub stars:** 90
- **License:** MIT
- **Skill name:** go-error-handling
- **Collection:** https://github.com/eduardo-sl/go-agent-skills
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-02

## About

This skill gives a coding agent a set of rules for creating, wrapping, checking and returning errors in Go projects. It includes a short decision tree for choosing between plain errors, wrapped errors, sentinel values and custom types, along with guidance on when to break the error chain with %v instead of %w.

The workflow covers the common mistakes it targets: comparing errors with ==, logging and returning the same error, leaking internal error text into responses, and custom types that hide their cause from errors.Is and errors.As. It also explains how to use errors.Join for collected failures and how to translate domain errors at HTTP and RPC boundaries. A reference file with checking patterns and examples is loaded on demand.

The skill expects a Go project with the Go toolchain installed. It suggests running go vet and golangci-lint with errcheck and errorlint enabled when those tools are available, and it notes that errors.AsType applies only on Go 1.26 and later.

## When your agent uses it

> Go error handling patterns, wrapping, sentinel errors, custom error types, and the errors package. Grounded in Effective Go, Go Code Review Comments, and production-proven idioms. Use when implementing error handling, designing error types, debugging error chains, or reviewing error handling patterns. Trigger examples: "handle errors", "error wrapping", "custom error type", "sentinel errors", "errors.Is", "errors.As". Not for: panic/recover in middleware (go-api-design), test assertions (go-test-quality).

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(code-quality)/go-error-handling)
- [Asks for: Read, Edit, Write, Glob, Grep, Bash(go:*), Bash(gofmt:*)](https://github.com/eduardo-sl/go-agent-skills/blob/HEAD/skills/(code-quality)/go-error-handling/SKILL.md)
- [License: MIT](https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(code-quality)/go-error-handling)

## Features

- **Error decision tree:** A quick guide for choosing between errors.New, fmt.Errorf wrapping, sentinel values and custom types.
- **Sentinel error patterns:** Naming and checking package-level sentinel errors with errors.Is instead of direct comparison.
- **Custom error types:** Structured error types with Unwrap support so the error chain remains walkable.
- **Wrapping and boundaries:** Rules for adding context with %w and translating errors before they reach users.
- **Single handling rule:** Guidance to log or return an error once, not both, and to keep log messages stable.
- **Lint verification:** Suggested go vet and golangci-lint checks for unchecked errors and misused wrapping.

## Good for

- Add context to errors returned from a database call in a Go service
- Design a custom error type that carries a field name for validation failures
- Replace direct error comparisons with errors.Is checks
- Review a Go package for log-and-return error handling
- Hide internal database errors from an exported API response

## Install

### Any agent

Download the skill folder from https://github.com/eduardo-sl/go-agent-skills and copy it into your agent's skills folder.

## FAQ

### Which tools does the skill need?

It needs the Go toolchain. Its allowed tools include Go and gofmt commands, and it suggests running go vet and golangci-lint when they are installed.

### Does Go error handling change Go version behavior?

No. It shows errors.AsType for Go 1.26 and later and errors.As for earlier versions, so the agent can use whichever fits the project.

### When should an error be wrapped with %w versus %v?

Use %w to keep the chain for callers inside the module. Use %v when you want to hide an internal error from a public API.

### Is the skill free to use?

It is released under the MIT license.

### Does Go error handling run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Go error handling?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Go error handling?

The closest alternatives to Go error handling are Error handling, Go backend, Go defensive coding, Go coding standards and M06 error handling.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Error handling](https://ai-powered.com/skills/error-handling): Error handling is an open-source agent skill for developer tools.
- [Go backend](https://ai-powered.com/skills/go-backend): Go backend is an open-source agent skill for developer tools.
- [Go defensive coding](https://ai-powered.com/skills/go-defensive-coding): Go defensive coding is an open-source agent skill for developer tools.
- [Go coding standards](https://ai-powered.com/skills/go-coding-standards): Go coding standards is an open-source agent skill for developer tools.
- [M06 error handling](https://ai-powered.com/skills/m06-error-handling): M06 error handling is an open-source agent skill for developer tools.
- [Go code review](https://ai-powered.com/skills/go-code-review): Go code review is an open-source agent skill for developer tools.
- [Go interface design](https://ai-powered.com/skills/go-interface-design): Go interface design is an open-source agent skill for developer tools.
- [Go CLI](https://ai-powered.com/skills/go-cli): Go CLI is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/go-error-handling
