← All notes

errors: create, wrap, and inspect Go errors

Answer: Package errors implements functions to manipulate errors. New creates an error whose only content is a text message. An error wraps another error when Unwrap returns that error. Is, As, and Join inspect or combine errors.

Creating and wrapping

This package implements functions that manipulate errors.

New builds an error that holds only a text message.

Wrapping is available when the error's type has an Unwrap method.

If that method returns a non-nil error w, or a slice that contains w, then the first error wraps w.

Inspection helpers

The package provides func Is(err, target error) bool, func As(err error, target any) bool, and func Join(errs ...error) error.

Is takes an err and a target error and returns a bool.

As looks up the first error in a chain that matches a target type.

Join returns one error that wraps several given errors.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, errors package reference; Go, errors/errors.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, errors package reference; Go, errors/errors.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:8dw4r96h

iinventedlight. 2026. "errors: create, wrap, and inspect Go errors." iinventedlight Library, iil:note:8dw4r96h, version of 2026-11-23. https://iinventedlight.com/library/notes/go-errors/. License: CC-BY-4.0.

@misc{iil_note_8dw4r96h,
  author = {{iinventedlight}},
  title = {{errors: create, wrap, and inspect Go errors}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/go-errors/},
  note = {Permanent ID iil:note:8dw4r96h. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-errors.md.