# pkg/errors

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/pkg-errors).**

8,258 stars · 715 forks · Go · BSD-2-Clause

## Links

- GitHub: https://github.com/pkg/errors
- Homepage: https://godoc.org/github.com/pkg/errors
- awesome-repositories: https://awesome-repositories.com/repository/pkg-errors.md

## Description

pkg/errors is a Go library that provides primitives for creating, annotating, and inspecting errors with stack traces and contextual information. Its core identity centers on capturing the call stack at the point of error creation or wrapping, preserving that information for later debugging and root cause analysis.

The library distinguishes itself through a set of tightly integrated capabilities for error handling. It supports wrapping errors with descriptive messages while recording a new stack trace at the wrapping point, annotating existing errors with either a message or a stack trace independently, and creating new errors that automatically capture the call stack. For inspection, it provides mechanisms to walk the wrapped error chain to retrieve the root underlying cause or to search through the chain for an error matching a specific type or value.

Error formatting is handled through Go's standard formatting verbs, allowing developers to conditionally print stack trace details alongside error messages for diagnostic purposes. The library's design forms a linked chain of wrapped errors, enabling traversal from the outermost context down to the original error.

## Tags

### Development Tools & Productivity

- [Stack Trace Capture](https://awesome-repositories.com/f/development-tools-productivity/custom-component-wrapping/error-boundary-wrappers/stack-trace-capture.md) — Captures the call stack at the point of error creation or wrapping for later inspection.
- [Stack Trace Creators](https://awesome-repositories.com/f/development-tools-productivity/custom-component-wrapping/error-boundary-wrappers/stack-trace-capture/stack-trace-creators.md) — Creates new error values that record the stack trace at the point of creation. ([source](http://godoc.org/github.com/pkg/errors))
- [Stack Trace Annotators](https://awesome-repositories.com/f/development-tools-productivity/custom-component-wrapping/error-boundary-wrappers/stack-trace-capture/stack-trace-annotators.md) — Adds a stack trace to an existing error without adding a new message. ([source](http://godoc.org/github.com/pkg/errors))

### Software Engineering & Architecture

- [Chain Type Matchers](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/error-management/error-type-compositions/chain-type-matchers.md) — Searches through the error chain to find the first error matching a target type or value. ([source](http://godoc.org/github.com/pkg/errors))
- [Error Wrapping](https://awesome-repositories.com/f/software-engineering-architecture/error-reporting/custom-error-interfaces/error-wrapping.md) — Wraps errors with descriptive messages while preserving the original error for chain traversal.
- [Chain Inspectors](https://awesome-repositories.com/f/software-engineering-architecture/error-reporting/custom-error-interfaces/error-wrapping/chain-inspectors.md) — Searches through wrapped error chains to find matching errors or retrieve the root cause.
- [Stack Trace Wrappers](https://awesome-repositories.com/f/software-engineering-architecture/error-reporting/custom-error-interfaces/error-wrapping/stack-trace-wrappers.md) — Records stack traces at error creation and wrapping points for debugging.
- [Error Cause Mapping](https://awesome-repositories.com/f/software-engineering-architecture/failure-handling-policies/success-and-failure-wrapping/failure-cause-extraction/error-cause-mapping.md) — Provides a function to unwrap the error chain and retrieve the root underlying cause.
- [Stack Trace Formatters](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/format-error-translators/terminal-error-formatting/stack-trace-formatters.md) — Prints errors with optional detailed stack trace information using standard formatting verbs.
- [Message Annotators](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/localized-error-messages/display-based-error-messages/message-annotators.md) — Adds a descriptive message to an existing error without recording a new stack trace. ([source](http://godoc.org/github.com/pkg/errors))
- [Format Verb Stack Printers](https://awesome-repositories.com/f/software-engineering-architecture/stacks/stack-trace-formatters/error-stack-filtering/format-verb-stack-printers.md) — Ships error formatting that prints stack traces conditionally via Go's fmt formatting verbs.
- [Format Verb Stack Printers](https://awesome-repositories.com/f/software-engineering-architecture/stacks/stack-trace-formatters/stack-trace-generation/format-verb-stack-printers.md) — Prints detailed stack trace information using standard formatting verbs.

### Part of an Awesome List

- [Error Handling](https://awesome-repositories.com/f/awesome-lists/devtools/error-handling.md) — Error handling with stack traces.
