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
- id: C1 claim: Package errors implements functions to manipulate errors. source: S1 evidence: "Package errors implements functions to manipulate errors."
- id: C2 claim: New creates an error whose only content is a text message. source: S1 evidence: "creates errors whose only content is a text message"
- id: C3 claim: An error wraps another error when Unwrap returns it. source: S2 evidence: "then we say that e wraps w"
- id: C4 claim: The package provides Is, As, and Join. source: S1 evidence: "func Join(errs ...error) error"
Sources
- [S1] errors package reference. Go. https://pkg.go.dev/errors . License: BSD-3-Clause. Accessed 2026-11-23.
- [S2] errors/errors.go source. Go. https://go.dev/src/errors/errors.go . License: BSD-3-Clause. Accessed 2026-11-23.
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
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.},
}
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.
- go-errors.schema.json (schema; CC-BY-4.0)
- go-errors.table.json (table; CC-BY-4.0)
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.