Skip to content

Commit

Permalink
flac: use errors.Cause(err) to compare against specific error values …
Browse files Browse the repository at this point in the history
…(e.g. io.EOF)

Updates #22.
  • Loading branch information
mewmew committed May 25, 2018
1 parent e917bb0 commit 0884ed7
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/flac2wav/flac2wav.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func flac2wav(path string) error {
// Decode FLAC audio samples.
frame, err := stream.ParseNext()
if err != nil {
if err == io.EOF {
if errors.Cause(err) == io.EOF {
break
}
return errors.WithStack(err)
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ExampleOpen() {
// subframe per audio channel.
frame, err := stream.ParseNext()
if err != nil {
if err == io.EOF {
if errors.Cause(err) == io.EOF {
break
}
log.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions flac.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func New(r io.Reader) (stream *Stream, err error) {
// Skip the remaining metadata blocks.
for !isLast {
block, err := meta.New(br)
if err != nil && err != meta.ErrReservedType {
if err != nil && errors.Cause(err) != meta.ErrReservedType {
return stream, errors.WithStack(err)
}
if err = block.Skip(); err != nil {
Expand Down Expand Up @@ -171,7 +171,7 @@ func Parse(r io.Reader) (stream *Stream, err error) {
for !isLast {
block, err := meta.Parse(br)
if err != nil {
if err != meta.ErrReservedType {
if errors.Cause(err) != meta.ErrReservedType {
return stream, errors.WithStack(err)
}
// Skip the body of unknown (reserved) metadata blocks, as stated by
Expand Down
2 changes: 1 addition & 1 deletion frame/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func (frame *Frame) correlate() {
// unexpected returns io.ErrUnexpectedEOF if err is io.EOF, and returns err
// otherwise.
func unexpected(err error) error {
if err == io.EOF {
if errors.Cause(err) == io.EOF {
return io.ErrUnexpectedEOF
}
return errors.WithStack(err)
Expand Down
6 changes: 3 additions & 3 deletions frame/frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestFrameHash(t *testing.T) {
for frameNum := 0; ; frameNum++ {
frame, err := stream.ParseNext()
if err != nil {
if err == io.EOF {
if errors.Cause(err) == io.EOF {
break
}
t.Errorf("i=%d, frameNum=%d: error while parsing frame; %v", i, frameNum, err)
Expand Down Expand Up @@ -72,7 +72,7 @@ func BenchmarkFrameParse(b *testing.B) {
for {
_, err := stream.ParseNext()
if err != nil {
if err == io.EOF {
if errors.Cause(err) == io.EOF {
break
}
stream.Close()
Expand All @@ -98,7 +98,7 @@ func BenchmarkFrameHash(b *testing.B) {
for {
frame, err := stream.ParseNext()
if err != nil {
if err == io.EOF {
if errors.Cause(err) == io.EOF {
break
}
stream.Close()
Expand Down
2 changes: 1 addition & 1 deletion frame/utf8.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func decodeUTF8Int(r io.Reader) (n uint64, err error) {
n <<= 6
c, err := readByte(r)
if err != nil {
if err == io.EOF {
if errors.Cause(err) == io.EOF {
return 0, io.ErrUnexpectedEOF
}
return 0, errors.WithStack(err)
Expand Down
3 changes: 2 additions & 1 deletion internal/bits/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ func TestReadEOF(t *testing.T) {

for i, test := range tests {
r := NewReader(bytes.NewReader(test.data))
if _, err := r.Read(test.n); err != test.err {
_, e := r.Read(test.n)
if err := errors.Cause(e); err != test.err {
t.Errorf("i=%d; Reading %d from %v, expected err=%s, got err=%s", i, test.n, test.data, test.err, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (t Type) String() string {
// unexpected returns io.ErrUnexpectedEOF if err is io.EOF, and returns err
// otherwise.
func unexpected(err error) error {
if err == io.EOF {
if errors.Cause(err) == io.EOF {
return io.ErrUnexpectedEOF
}
return errors.WithStack(err)
Expand Down

0 comments on commit 0884ed7

Please sign in to comment.