Skip to content

Commit

Permalink
meta: fix issue with errors.WithStack, io.Copy expect io.EOF
Browse files Browse the repository at this point in the history
We cannot use errors.WithStack [1] to maintain call stack information
of zeros.Read as this method is invoked from io.Copy (in verifyPadding)
which expects io.EOF.

Note, the type of the returned error in the case of EOF becomes,
"errors.withStack" with the concrete value:
	errors.withStack{error: io.EOF, stack: callers()}

This broke the tests:

https://travis-ci.org/mewkiz/flac/builds/383805346#L540

We cannot update the standard library to check for io.EOF
using errors.Cause(err) == io.EOF. Thus, this seems like the
only solution.

Unfortunate, and a bit scare, as there may be other use of
interfaces which break since the error returned is wrapped
with added context.

Hope this gets resolved in Go 2. I know @bradfitz among others
have raised their interest in finding ways to improve and further
simplify error handling mechanisms [2].

[1]: https://github.com/pkg/errors
[2]: https://github.com/golang/go/wiki/Go2

Updates #22.

Related to golang/go#21161.
  • Loading branch information
mewmew committed May 25, 2018
1 parent 0884ed7 commit 6805a34
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion meta/padding.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ func (zr zeros) Read(p []byte) (n int, err error) {
return n, ErrInvalidPadding
}
}
return n, errors.WithStack(err)
// Note, not wrapping err in errors.WithStack as it will confuse io.Copy
// which is expecting io.EOF.
return n, err
}

0 comments on commit 6805a34

Please sign in to comment.