errors

Simple Go error handling primitives that add stack traces and context without losing the original cause.

Library
Go
vv0.9.1
8,257 stars
BSD-2-Clause

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
48 /100 Fair
Development Activity 4
Maintenance 20
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
61 /100 Good
Architecture 70
Code Quality 80
Innovation 30
Learning Curve 65

pkg/errors gives Go programs a small set of primitives for annotating errors as they travel up the call stack. Instead of the bare if err != nil { return err } idiom, which throws away debugging context on every return, functions like Wrap and WithStack record a stack trace and an optional message at the point they’re called, while leaving the original error value intact underneath.

Callers that need to inspect the underlying failure can call Cause to unwrap back to the root error, or use the unexported causer and stackTracer interfaces the package documents as part of its stable public API. All returned errors implement fmt.Formatter, so %+v prints the full annotated stack trace alongside the message. A go113.go file bridges the package to the standard library’s Is/As/Unwrap, so it composes with Go 1.13+ error chains without breaking existing call sites.

What You Get

  • Wrap and Wrapf to attach a message and stack trace to an existing error in one call
  • WithStack and WithMessage for attaching just a stack trace or just a message when you need finer control
  • Cause to walk back through a chain of wrapped errors to the original underlying error
  • fmt.Formatter support so %+v prints the message plus a full multi-frame stack trace
  • Compatibility shims (Is, As, Unwrap) for Go 1.13+ standard error chains

Common Use Cases

  • Wrapping errors returned from I/O, database, or network calls with a human-readable message and a stack trace for later debugging
  • Logging or reporting tools that print %+v on an error to get file/line stack traces without a separate tracing library
  • Type-switching on the root cause of a wrapped error via errors.Cause to handle specific error types deep in a call chain
  • Bridging legacy code that used pkg/errors with newer code relying on Go 1.13’s errors.Is/As/Unwrap chain semantics

Under The Hood

Architecture

The package is a single flat unit with no internal layering: errors.go defines the wrapper constructors (New, Errorf, WithStack, Wrap, Wrapf, WithMessage, WithMessagef) and the Cause accessor, stack.go implements the Frame/StackTrace/stack types plus the callers() helper that captures runtime.Callers at each wrap site, and go113.go (behind a go1.13 build tag) re-exports the standard library’s Is/As/Unwrap for chain compatibility. There is no dependency injection or multi-layer data flow — the only composition is struct embedding, where withStack embeds *stack and withMessage wraps a cause plus a message, with behavior surfaced entirely through the Error(), Format(), and unexported causer interfaces. Because every wrapper type embeds *stack directly, any change to callers() or the stack format would propagate to all of them at once — an intentional, tightly coupled design appropriate to a package this small and stable.

Tech Stack

There is no go.mod in the repository (the package predates widespread Go modules adoption and is consumed at its tagged v0.9.1 release), and it has zero external dependencies — only the Go standard library (fmt, io, path, runtime, strconv, strings, and the stdlib errors package in go113.go). Build tooling is a minimal Makefile wrapping go test/go vet, with CI configured through legacy providers (Travis CI and AppVeyor) rather than GitHub Actions. There is nothing to deploy; consumers simply go get and import the package.

Code Quality

Test coverage is extensive relative to the package’s size: errors_test.go, stack_test.go, format_test.go, bench_test.go, example_test.go, go113_test.go, and json_test.go exercise essentially every exported function, including every fmt verb combination (%s/%v/%+v/%q) and JSON marshaling edge cases, using table-driven tests and Go’s Example* convention for documentation-verified output. Error handling is the subject matter itself — errors are modeled as explicit typed structs (fundamental, withStack, withMessage) rather than being swallowed anywhere. Naming is idiomatic Go, the type surface is minimal, and CI runs across multiple Go versions, though via legacy CI providers with no modern linter configuration visible.

What Makes It Unique

The package isn’t attempting anything technically novel today — Go’s standard library has since absorbed similar behavior via fmt.Errorf’s %w verb and errors.Is/As/Unwrap in Go 1.13, which the package’s own go113.go file explicitly bridges to. Its real significance was historical: from roughly 2015 to 2019 it was the de facto standard for stack-trace-carrying error wrapping in Go, popularizing the causer/Cause() pattern that influenced the language’s eventual native %w support. The README itself states the package has moved into maintenance mode, so today it functions as a stable, frozen legacy dependency many large codebases still depend on rather than an active point of innovation.

Used by 33 apps in this directory

Go
69%
Other

Hanko

Authentication · Security

9,045

Open source, self-hostable authentication platform with passkeys, SAML SSO, and OAuth — the privacy-first alternative to Auth0 and Clerk.

View details
90
Repo Health
81
Technical
66
Dependency
Built with
Go 69%
TypeScript 27%
Updated 1 weeks ago
Go
62%
Apache 2.0

Harness Open Source

Code Editors · Developer Tools · Devops

38,684

A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.

View details
90
Repo Health
79
Technical
64
Dependency
Built with
Go 62%
TypeScript 33%
Updated 1 weeks ago
TypeScript
71%
Other

highlight.io

Analytics · Developer Tools · Monitoring

9,384

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
76
Repo Health
78
Technical
65
Dependency
Built with
TypeScript 71%
Go 16%
Updated 1 weeks ago
Go
69%
MIT

hoop

Monitoring · Security

836

A wire-protocol gateway that enforces data masking, command blocking, approval workflows, and full session recording for engineers and AI agents accessing production infrastructure.

View details
86
Repo Health
80
Technical
64
Dependency
Built with
Go 69%
Clojure 13%
Updated 6 days ago
TypeScript
62%
EPL-2.0

Huly Platform

Collaboration · Project Management · Team Chat

27,978

Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.

View details
90
Repo Health
86
Technical
62
Dependency
Built with
TypeScript 62%
Svelte 34%
Updated 1 weeks ago
Go
97%
Apache 2.0

infracost

Developer Tools · Devops

12,585

Infracost shows cloud cost estimates for Terraform, CloudFormation, and AWS CDK before you deploy — in your terminal, editor, AI coding agent, and pull requests.

View details
83
Repo Health
78
Technical
68
Dependency
Built with
Go 97%
Updated 1 weeks ago
Go
97%
Apache 2.0

kopia

File Storage

14,417

Fast, encrypted, deduplicated backups to any cloud or local storage with full client-side control.

View details
90
Repo Health
83
Technical
68
Dependency
Built with
Go 97%
Updated 1 weeks ago
Go
97%
MIT

Formance Ledger

Databases · Developer Tools · Invoicing Finance

1,448

The programmable open source core ledger for fintech — build money-moving applications with atomic multi-posting transactions, account-based modeling, and Numscript, a built-in DSL for financial logic.

View details
91
Repo Health
8
Technical
68
Dependency
Built with
Go 97%
Updated 6 days ago
TypeScript
51%
Other

Mattermost

Collaboration · Devops · Team Chat

39,418

Open core, self-hosted team collaboration with chat, AI agents, voice calling, and deep DevOps integrations — all under your control.

View details
96
Repo Health
87
Technical
65
Dependency
Built with
TypeScript 51%
Go 40%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers