---
title: "Go error handling: error values, wrapping, errors.Is and As"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source: https://iinventedlight.com/library/notes/go-error-handling.md
source_license: "CC BY 4.0 (go.dev text); restated in our own words"
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Go Authors (go.dev), Error handling and Go - The Go Programming Language, CC BY 4.0 (go.dev text); The Go Authors (go.dev), Working with Errors in Go 1.13 - The Go Programming Language, CC BY 4.0 (go.dev text)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run; only the fetched documentation pages were read."
category: coding-references
topic_area: "go: errors"
tags: go, golang, errors, error-handling
sources:
  - id: S1
    title: "Error handling and Go - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/blog/error-handling-and-go
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
  - id: S2
    title: "Working with Errors in Go 1.13 - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/blog/go1.13-errors
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
---
# Go error handling: error values, wrapping, errors.Is and As

## Short answer
Go functions return an `error` as the last result; check `if err != nil` right away. Wrap with `fmt.Errorf("...: %w", err)` and inspect with `errors.Is` (compare to a value) or `errors.As` (get a type). [S1][S2]

## Example
```go
f, err := os.Open(name)
if err != nil {
    return fmt.Errorf("open config: %w", err)
}
```

## Why
`error` is just an interface with an `Error() string` method, so any type can carry extra detail. [S1][S2]

## Claims
- id: C1
  claim: Go uses error values to indicate abnormal state.
  source: S1
  evidence: "Go code uses error values to indicate an abnormal state."
- id: C2
  claim: The error type is an interface.
  source: S1
  evidence: "The error type is an interface type."
- id: C3
  claim: Go 1.13 added errors.Is and errors.As.
  source: S2
  evidence: "includes two new functions for examining errors: Is and As"
- id: C4
  claim: errors.Is compares an error to a value.
  source: S2
  evidence: "function compares an error to a value"

## Sources
- [S1] Error handling and Go - The Go Programming Language. The Go Authors (go.dev). https://go.dev/blog/error-handling-and-go . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
- [S2] Working with Errors in Go 1.13 - The Go Programming Language. The Go Authors (go.dev). https://go.dev/blog/go1.13-errors . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
