peterbourgon / diskv

A disk-backed key-value store.
http://godoc.org/github.com/peterbourgon/diskv
MIT License
1.4k stars 102 forks source link

Read: always return nil slice on error #47

Closed ghost closed 6 years ago

ghost commented 6 years ago

This lets one more easily distinguish between a key that doesn't exist and an existing key with an empty value.

peterbourgon commented 6 years ago

I don't quite understand the rationale here, and I don't understand the "fix". If a key doesn't exist, Read will return a non-nil error. If a key exists with an empty value, Read will (should?) return a nil error.

Additionally, by convention, if any function returns non-nil error, the other return values should be considered undefined. Doing any comparison on return values in the presence of a non-nil error is probably incorrect, and so I'm hesitant there, too.

ghost commented 6 years ago

I want to be able to perform one comparison, not two.

Additionally, by convention, if any function returns non-nil error, the other return values should be considered undefined.

I doubt it. AFAIK all the stdlib functions return zero value in case of an error, except some readers where partial content could be useful. But okay, feel free to close this PR, I'll just use my fork then.

peterbourgon commented 6 years ago

Additionally, by convention, if any function returns non-nil error, the other return values should be considered undefined.

I doubt it.

(shrug) It's idiomatic. Phrased another way,

[We should] give no guarantee whatsoever of the state of the other return values in the presence of an error.

https://groups.google.com/d/msg/golang-nuts/lcZNt-nMsl0/rIzW91kICAAJ


I'll just use my fork then.

👍