Migrate error comparisons to errors.Is/errors.As#84
Draft
bobheadxi wants to merge 1 commit into
Draft
Conversation
| var e0 *ParseError | ||
| if errors.As(err, &e0) { | ||
| var e *ErrBadHunkLine | ||
| if errors.As(e0.Err, &e) { |
Member
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) { |
Member
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
requested changes
Jun 17, 2026
Member
Author
|
@keegancsmith sorry I hit publish on this while practicing a demo, this is just a test case 🙇 |
Member
|
@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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.