oschwald / maxminddb-golang

MaxMind DB Reader for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error from close is not propagated outside

graywolf-at-work opened this issue · comments

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

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.

Thanks! This was fixed in df020c7.