Migrate error comparisons to errors.Is/errors.As#84
Conversation
| var e0 *ParseError | ||
| if errors.As(err, &e0) { | ||
| var e *ErrBadHunkLine | ||
| if errors.As(e0.Err, &e) { |
There was a problem hiding this comment.
We should add the Unwrap method to ParseError in this PR then we can simplify this and other places so we don't first have to check for ParseError
| if pe, ok := err.(*ParseError); ok && pe.Err == ErrExtendedHeadersEOF { | ||
| var pe *ParseError | ||
| var oe OverflowError | ||
| if errors.As(err, &pe) && errors.Is(pe.Err, ErrExtendedHeadersEOF) { |
There was a problem hiding this comment.
code like this make me nervous in general, but I believe its correct. IE we are relying on the first condition to mutate pe so that the second condition doesn't nil panic on pe.Err
|
@keegancsmith sorry I hit publish on this while practicing a demo, this is just a test case 🙇 |
|
@bobheadxi I thought that might be the case, but being able to handle follow-up comments seems like a good test case for testing BCA :) Do you plan on following up with this? |
When we build comment follow-ups 😉 (aka not yet, I'm using this migration example a lot and it's nice to have this repo as a test target. we should invest in more synthetic repos and examples soon) |
This change migrates direct error comparisons and error type assertions to the
modern
errorspackage idioms:err == SentinelErr/err != SentinelErr->errors.Is(err, SentinelErr)/!errors.Is(...)for sentinels such as
sql.ErrNoRows,context.Canceled,context.DeadlineExceeded,http.ErrServerClosed,io.ErrUnexpectedEOF,os.ErrNotExist, etc.switch err.(type)classification ->errors.As.Excluded by design:
io.EOFcomparisons (idiomatic in reader loops) and_test.gofiles.This makes error checks robust to wrapped errors (
fmt.Errorf("...: %w", err)).Generated by a Sourcegraph batch change.
Created by Sourcegraph batch change
robert/58006530-3ddc-4c11-ad42-8d8eed8bc63f.