go-error

Implement idiomatic Go error wrapping, custom types, and chain inspection.

Updated Dec 31, 2025
One-click install
npx skills add https://github.com/victorzhuk/go-ent --skill go-error
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-error
Source: https://github.com/victorzhuk/go-ent/tree/main/pkg/skills/go/go-error
Command: npx skills add https://github.com/victorzhuk/go-ent --skill go-error

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers implement robust and idiomatic Go error handling, ensuring clear context, proper error chaining, and effective error management in production applications.

Core Features & Use Cases

  • Error Wrapping: Learn to use fmt.Errorf with %w to add context while preserving the original error.
  • Custom Error Types: Define custom error types with Error() methods and optional Is()/Unwrap() for specific error conditions.
  • Sentinel Errors: Understand how to use errors.New() for comparable error values and check them with errors.Is().
  • Error Chains: Inspect complex error chains using errors.Is() and errors.As() to handle specific error types or values.
  • Use Case: Debugging a complex service where errors propagate through multiple layers. This Skill guides you on how to wrap errors at each layer with relevant context and how to inspect the full error chain at the top level to identify the root cause.

Quick Start

Provide guidance on implementing Go error wrapping across multiple application layers.

Frequently Asked Questions about go-error

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add context to a Go error without losing the original error?

To add context to a Go error without losing the original, use error wrapping with `fmt.Errorf` and the `%w` verb. This preserves the original error in the chain, allowing callers to inspect the root cause while reading the added contextual information.

What is the difference between errors.Is() and errors.As() in Go error chains?

When inspecting Go error chains, `errors.Is()` compares a specific error value against sentinel errors, while `errors.As()` checks if any error in the chain matches a target custom error type. `errors.Is` is for values, `errors.As` is for types.

How do I define custom error types with specific error conditions in Go?

To define custom error types in Go, create a struct that implements the `Error()` method. You can optionally implement `Is()` for custom comparison logic or `Unwrap()` to support error chaining for specific error conditions.

When should I use sentinel errors instead of custom error types in Go?

Use sentinel errors created with `errors.New()` when you need comparable error values to check specific expected conditions. Use custom error types when errors must carry additional structured data or require specific type assertions for robust error handling.

What is the best way to handle Go error propagation across multiple application layers?

The best way to handle Go error propagation across multiple layers is to wrap errors at each layer with relevant context using `fmt.Errorf`. At the top level, inspect the full error chain using `errors.Is` or `errors.As` to identify the root cause.