talira

pkg/errors

Simple error handling primitives for Go: wrap errors with context and stack traces

open sourceBSD-2-Clauseself-hostablefree

pkg/errors is a small Go library for adding context to errors as they travel up the call stack. errors.Wrap and errors.Wrapf add a message and a stack trace to an error, errors.Cause unwraps it to the original, and formatting with %+v prints the stack. Since the Go 2 error proposals it has been in maintenance mode: it takes bug fixes but no new features, and its last code change was in 2020.

Problems it solves

  • add context to errors in Go without losing the original error
  • get a stack trace for where an error happened in my Go code
  • find the root cause of a wrapped error in Go

Features

  • Wrap and Wrapf add context and a stack trace
  • Cause returns the original error
  • %+v prints the stack trace

Limitations

  • In maintenance mode: it accepts bug fixes but no new features.1

Capabilities

Has official SDKsplan not known