go: encoding/gob: better support for error
Errors created by the errors package are not registered with encoding/gob
which is necessary in order to send them as results of remote procedure calls.
By now, returning an error from the standard library through an RPC method will cause that the receiver get an EOF error
and the transmitter a gob: type not registered for interface: errors.errorString
My proposal is add an init()
function in the errors package to register the struct errorString
so then, developers will avoid create its own errors implementation when using RPCs.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 16 (10 by maintainers)
Commits related to this issue
- Convert errors to serializable errors Plain errors cannot be serialized over gRPC without some gob work so this change makes use of the internal BasicError type from go-plugin to send the information... — committed to sgnn7/golang-grpc-plugin-test by sgnn7 5 years ago
- Return nil if the error string is empty. Again, we cannot use an error type here (which would be significantly more convenient) because of the following issue: <https://github.com/golang/go/issues/23... — committed to NullHypothesis/bridgestrap by NullHypothesis 4 years ago
Rather than teach gob about one particular way of making errors, a better plan might be to have gob implement a fallback for errors in general. If something implements the error interface, gob could arrange to transmit the string and recover the error value on the other side, automatically. For those who want richer, type-aware semantics for errors, for example as is done in https://github.com/upspin/upspin/tree/master/errors, one can always implement one of the standard marshaling interfaces for that type, which would override the default.
I’ve been thinking about doing this for a while; perhaps the time has come to do something.
@robpike will look into doing something for Go 1.11.
Can you show some code demonstrating where this is needed? Thanks.