errors types
In a recent pull request, @cel showed that we need different behaviour depending on the different types of errors. https://github.com/ssbc/ssb-ebt/pull/2
I think this is definitely something we need, but I'm wary of using the error messages for that. Because that would make the error messages a public api, not just a user interface. That would mean we couldn't improve the error messages to be something more obvious for the human, because it might break code that looks at the message.
HTTP has status codes, 2xx it worked, 3xx it's somewhere else, 4xx failed, your fault. 5xx failed my fault. I don't think the same codes will work for us, though.
what about, flags for the reason, one of more can be true.
- network: a connection failed somehow, or network unavailable
- cryptography: could not authenticate, decrypt, or a something had the wrong hash.
- api: an api did not exist, or signature used was invalid.
- fs: a file didn't exist, or couldn't be written to.
https://github.com/ssbc/scuttlebot/pull/374 is another PR that involves checking errors. All of these errors would be network
type.
But in https://github.com/ssbc/ssb-ebt/pull/2 there is a distinction between a network failure (means the stream is closed) and an api failure (which means ebt is not supported, so carry on)
Okay so my proposal is errors have a small set of keys say, network, crypto, api, fs
(suggestions welcome) and then those have properties which are a single camel cased string which identifies the particular error. This would be intended as machine readable, so no changing this once you have made the error.
Bikeshedders, prepare your naming hammers.