-
Couldn't load subscription status.
- Fork 18.4k
ErrorValueFAQ
The Go 2 error values proposal adds functionality to the errors and fmt packages of the standard library for Go 1.13. There is also a compatibility package, golang.org/x/xerrors, for earlier Go versions.
We suggest using the xerrors package for backwards compatibility. When you no longer wish to support Go versions before 1.13, use the corresponding standard library functions.
You need to be prepared that errors you get may be wrapped.
-
If you currently compare errors using
==, usexerrors.Isinstead. Example:if err == io.ErrUnexpectedEOFbecomes
if xerrors.Is(err, io.ErrUnexpectedEOF) -
Checks of the form
if err == nilneed not be changed. -
Comparisons to
io.EOFneed not be changed, becauseio.EOFshould never be wrapped.