-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ package enmime | |
import ( | ||
"bufio" | ||
"bytes" | ||
"errors" | ||
"io" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func TestBoundaryReader(t *testing.T) { | ||
|
@@ -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 { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
t.Fatal("Read() should have returned bufio.ErrBufferFull error, failed") | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,12 @@ package enmime | |
import ( | ||
"bufio" | ||
"bytes" | ||
"errors" | ||
"io" | ||
|
||
"github.com/jhillyerd/enmime/internal/coding" | ||
"github.com/jhillyerd/enmime/internal/textproto" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
var defaultHeadersList = []string{ | ||
|
@@ -39,9 +40,10 @@ func DecodeHeaders(b []byte, addtlHeaders ...string) (textproto.MIMEHeader, erro | |
b = ensureHeaderBoundary(b) | ||
tr := textproto.NewReader(bufio.NewReader(bytes.NewReader(b))) | ||
headers, err := tr.ReadMIMEHeader() | ||
|
||
// io.EOF is expected | ||
if err != nil && !errors.Is(err, io.EOF) { | ||
switch errors.Cause(err) { | ||
case nil, io.EOF: | ||
// carry on, io.EOF is expected | ||
default: | ||
Comment on lines
+43
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous logic, using |
||
return nil, err | ||
} | ||
headerList := defaultHeadersList | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ import ( | |
"bufio" | ||
"bytes" | ||
"encoding/base64" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"math/rand" | ||
"mime/quotedprintable" | ||
|
@@ -17,6 +15,8 @@ import ( | |
"github.com/jhillyerd/enmime/internal/coding" | ||
"github.com/jhillyerd/enmime/internal/textproto" | ||
"github.com/jhillyerd/enmime/mediatype" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
const ( | ||
|
@@ -195,7 +195,7 @@ func (p *Part) convertFromDetectedCharset(r io.Reader, readPartErrorPolicy ReadP | |
|
||
buf, err := p.readPartContent(r, readPartErrorPolicy) | ||
if err != nil { | ||
return nil, err | ||
return nil, errors.WithStack(err) | ||
} | ||
|
||
cs, err := cd.DetectBest(buf) | ||
|
@@ -304,7 +304,7 @@ func (p *Part) decodeContent(r io.Reader, readPartErrorPolicy ReadPartErrorPolic | |
// Decode and store content. | ||
content, err := p.readPartContent(contentReader, readPartErrorPolicy) | ||
if err != nil { | ||
return p.base64CorruptInputCheck(fmt.Errorf("failed to decode content: %w", err)) | ||
return p.base64CorruptInputCheck(errors.WithStack(err)) | ||
} | ||
p.Content = content | ||
// Collect base64 errors. | ||
|
@@ -325,11 +325,12 @@ func (p *Part) decodeContent(r io.Reader, readPartErrorPolicy ReadPartErrorPolic | |
// | ||
// It can be used to create ReadPartErrorPolicy functions. | ||
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 | ||
} | ||
Comment on lines
327
to
334
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
} |
||
|
||
// base64CorruptInputCheck will avoid fatal failure on corrupt base64 input | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return err | ||
} | ||
if br.unbounded { | ||
|
@@ -464,7 +465,7 @@ func parseParts(parent *Part, reader *bufio.Reader) error { | |
// Store any content following the closing boundary marker into the epilogue. | ||
epilogue, err := io.ReadAll(reader) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse parts: %w", err) | ||
return errors.WithStack(err) | ||
} | ||
parent.Epilogue = epilogue | ||
|
||
|
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.