diff --git a/ErrorValueFAQ.md b/ErrorValueFAQ.md index 7142dd71..3dd4c436 100644 --- a/ErrorValueFAQ.md +++ b/ErrorValueFAQ.md @@ -26,7 +26,8 @@ You need to be prepared that errors you get may be wrapped. ``` becomes ``` - if e := &os.PathError{}; xerrors.As(err, &e) + e := &os.PathError{} + if xerrors.As(err, &e) ``` - Also use this pattern to check whether an error implements an interface. (This is one of those rare cases when a pointer to an interface is appropriate.) - Rewrite a type switch as a sequence of if-elses.