Skip to content

Commit

Permalink
Use errors.Is to detect wrapped EOF errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Mar 10, 2022
1 parent e120cdc commit ae38a94
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
9 changes: 5 additions & 4 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import (
"io"
"math"
"sort"
"errors"
{{ range .Imports }}{{ .Name }} "{{ .PkgPath }}"
{{ end }}
Expand Down Expand Up @@ -1043,8 +1044,8 @@ func (t *{{ .Name}}) UnmarshalCBOR(r io.Reader) (err error) {
return err
}
defer func() {
if err == io.EOF {
err = io.ErrUnexpectedEOF
if errors.Is(err, io.EOF) {
err = xerrors.Errorf("%w: %v", io.ErrUnexpectedEOF, err)
}
}()
Expand Down Expand Up @@ -1207,8 +1208,8 @@ func (t *{{ .Name}}) UnmarshalCBOR(r io.Reader) (err error) {
return err
}
defer func() {
if err == io.EOF {
err = io.ErrUnexpectedEOF
if errors.Is(err, io.EOF) {
err = xerrors.Errorf("%w: %v", io.ErrUnexpectedEOF, err)
}
}()
Expand Down
13 changes: 7 additions & 6 deletions testing/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions testing/cbor_map_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ae38a94

Please sign in to comment.