tidwall / buntdb

BuntDB is an embeddable, in-memory key/value database for Go with custom indexing and geospatial support
MIT License
4.57k stars 289 forks source link

Error checking #6

Closed olurin closed 8 years ago

olurin commented 8 years ago

Hi Josh, Nice project. I noticed that you didn't check some errors that are returned from your functions Example:

Is there a reason why you didn't check most errors? (I am trying to learn more about the best practices in Go language)

tidwall commented 8 years ago

Hi Anthony,

As a rule-of-thumb; If a function returns an error, then handle the error. But there are times when I don't check an error, and it's usually one of two reasons:

  1. The function can't return an error, even though the function signature has a return value.
  2. Failure is optional and sometimes OK, and I often don't care what the error message is.

I'll explain the reason for each of lines you provided:

This goes for the bufio.Writer.Write() calls too. I ignore all of the errors because an error under-the-hood is likely an out-of-memory situation and will panic the system. The only error I care about is whether or not the data was written to disk. https://github.com/muyiwaolurin/buntdb/blob/master/buntdb.go#L447

I try to handle as many errors as possible, but the truth is some of them just don't matter. I would rather not waste any CPU cycles on those.

I hope this information helps and good luck.

olurin commented 8 years ago

Thats awesome! Thanks Josh.