-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rollback pkg/errors portion of #298 #299
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using errors.Is()
and errors.As()
to compare error values and types (respectively), and to get inside wrapped errors, is the way to go. Not critical to do right this moment, but it'll make the code more resilient to future changes.
@@ -462,15 +463,15 @@ func TestBoundaryReaderReadErrors(t *testing.T) { | |||
if n != 0 { | |||
t.Fatal("Read() should not have read any bytes, failed") | |||
} | |||
if !errors.Is(err, bufio.ErrBufferFull) { | |||
if errors.Cause(err) != bufio.ErrBufferFull { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors.Is()
is probably better here, ultimately.
t.Fatal("Read() should have returned bufio.ErrBufferFull error, failed") | ||
} | ||
// Next method to return a non io.EOF error. | ||
next, err := br.Next() | ||
if next { | ||
t.Fatal("Next() should have returned false, failed") | ||
} | ||
if !errors.Is(err, bufio.ErrBufferFull) { | ||
if errors.Cause(err) != bufio.ErrBufferFull { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors.Is()
is probably better here, ultimately.
switch errors.Cause(err) { | ||
case nil, io.EOF: | ||
// carry on, io.EOF is expected | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous logic, using errors.Is()
, is probably better here.
func IsBase64CorruptInputError(err error) bool { | ||
if err == nil { | ||
switch errors.Cause(err).(type) { | ||
case base64.CorruptInputError: | ||
return true | ||
default: | ||
return false | ||
} | ||
_, ok := err.(base64.CorruptInputError) | ||
return ok | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func IsBase64CorruptInputError(err error) bool {
var errCorrupt base64.CorruptInputError
return errors.As(err, &errCorrupt)
}
@@ -406,7 +407,7 @@ func parseParts(parent *Part, reader *bufio.Reader) error { | |||
br := newBoundaryReader(reader, parent.Boundary) | |||
for indexPartID := 1; true; indexPartID++ { | |||
next, err := br.Next() | |||
if err != nil && !errors.Is(err, io.EOF) { | |||
if err != nil && errors.Cause(err) != io.EOF { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!errors.Is(io.EOF)
is probably better here, ultimately.
PR #298 removed usage of the archived package github.com/pkg/errors, and
references to the deprecated ioutil package.
After understanding that stdlib errors still does not support stack trace
wrapping (see discussion in #298), we have decided to rollback these changes
as parser debugging heavily benefits from stack traces.
The ioutil changes are desirable and will be kept.
See also #94