Skip to content
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

Merged
merged 1 commit into from
Aug 15, 2023
Merged

Rollback pkg/errors portion of #298 #299

merged 1 commit into from
Aug 15, 2023

Conversation

jhillyerd
Copy link
Owner

@jhillyerd jhillyerd commented Aug 14, 2023

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

@coveralls
Copy link

coveralls commented Aug 14, 2023

Coverage Status

coverage: 85.955% (-0.02%) from 85.97% when pulling e0550a7 on revert-298 into 3c35f97 on main.

@jhillyerd jhillyerd merged commit bb96b5a into main Aug 15, 2023
10 checks passed
@jhillyerd jhillyerd deleted the revert-298 branch August 15, 2023 00:55
Copy link
Contributor

@dcormier dcormier left a 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 {
Copy link
Contributor

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 {
Copy link
Contributor

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.

Comment on lines +43 to +46
switch errors.Cause(err) {
case nil, io.EOF:
// carry on, io.EOF is expected
default:
Copy link
Contributor

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.

Comment on lines 327 to 334
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
}
Copy link
Contributor

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 {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants