Working with Errors
summary
Go 1.13 adds three new functions in the errors package and the %w verb for fmt, and shows how wrapping preserves an underlying error so programs can use errors.Is and errors.As instead of brittle string checks; it demonstrates unwrap, %w usage, and the pointer-to-error pattern for type matches. It warns that wrapping becomes part of an API (so wrapping sentinel values like io.EOF is wrong), explains why no automatic stack traces or complex printf formatting made the stdlib, and describes a working defer+wrap pattern used at package.go.dev to add controlled traces.
AI-written summary · about
chapters (26)
- 0:00Intro
- 0:20Wrapping and the error chain
- 0:44Error-wrapping support in Go 1.13
- 1:11Two audiences for errors
- 1:59A Config struct
- 2:19User-facing function
- 2:32Deciding with errors before 1.13
- 3:12Annotating errors
- 3:45Error wrapping
- 3:57Wrapping errors in Go 1.13
- 4:35Use errors. As instead of type assertions
- 5:00Under the hood
- 7:34Moving to Wrapped Errors
- 8:10Wrapping Returned Errors
- 9:41Did we go too far?
- 10:25Errors and Codes
- 11:22Stack trace example
- 11:49Stack trace problems
- 12:51We tried...
- 14:05How we don't do it
- 15:07Execution Traces With Wrap
- 15:17Standard Formatting
- 15:53Detailed Formatting
- 16:09Formatting Removed
- 16:26Detail Formatting with fmt. Formatter
- 17:40References








