polyfloyd / go-errorlint

A source code linter that can be used to find code that will cause problems with Go's error wrapping scheme
MIT License
248 stars 19 forks source link

false positive on with `err == io.EOF` on `*bytes.Reader` #13

Closed trim21 closed 3 years ago

trim21 commented 3 years ago

this should be good:

type CompressedFile struct {
    reader             *bytes.Reader
    zipPath            string
}

func (c CompressedFile) Read(p []byte) (int, error) {
    n, err := c.reader.Read(p)
    if err == io.EOF { // report error here
        return n, io.EOF
    }

    return n, errors.Wrapf(err, "can't read from reader %s", c.zipPath)
}

( and yes, I know I should use io.Reader here instead of *bytes.Reader...

polyfloyd commented 3 years ago

Thanks for reporting!