Re:Eris – A better way to handle, trace, and log errors in Go
by tsimionescu on Thursday December 26, 2019 @02:37AM
(#21882506)
That's not exactly true. All struct types in Go can not be nil. However, they also can't be abstracted over in any way, so they are a poor idea for an error type - you want an error interface, and all interface types in Go indeed are nil-able.
[ Parent
| on HN ]
Re:Eris – A better way to handle, trace, and log errors in Go
by weberc2 on Thursday December 26, 2019 @10:00AM
(#21884221)
You can abstract over a struct as easily as a pointer, and structs work fine for satisfying interfaces. Specifically, structs make it a little harder for someone to inadvertently mutate things (passed by copy) and because they can’t be nil you don’t need to worry about a non-nil interface implemented by a nil concrete pointer (this is mostly only a problem for people who are new to pointers in my experience). The downside is every time you put a struct into an interface, it gets allocated on the heap, and allocations are expensive in Go (also passing structs can be more expensive than passing pointers).
Re:Eris – A better way to handle, trace, and log errors in Go
by tsimionescu on Thursday December 26, 2019 @12:05PM
(#21885122)
What I meant about abstraction is that if you define a function which returns an error struct instead of an error interface, you lose any abstraction capability, you can only return that specific struct (and need to find some way of signaling that no error occurred).