oschwald / maxminddb-golang

MaxMind DB Reader for Go
ISC License
576 stars 99 forks source link

Error from close is not propagated outside #68

Closed graywolf-at-work closed 4 years ago

graywolf-at-work commented 4 years ago

The error from os.Close is stored to err, which is the one created here https://github.com/oschwald/maxminddb-golang/blob/master/reader_other.go#L16 .

That means that the assigment here https://github.com/oschwald/maxminddb-golang/blob/302864b2c4f7766813dede5095da8ba442c00c7e/reader_other.go#L22 basically does nothing.

Either this https://github.com/oschwald/maxminddb-golang/blob/master/reader_other.go#L15 should be

func Open(file string) (r *Reader, err error) {

but since that would mask actual error with one from os.Close, I think better option would be to just replace

    defer func() {
        if rerr := mapFile.Close(); rerr != nil {
            err = rerr
        }
    }()

with

    defer func() {
        mapFile.Close()
    }()

As written right now the code probably does not do what was intended.

oschwald commented 4 years ago

Thanks! This was fixed in df020c7.