4 ms·
> To avoid encountering this issue, return `error`, not something else. But best practice is to return concrete types. Also, `err` is just an example in this
by hombre_fatal 8y ago
> To avoid encountering this issue, return `error`, not something else.
But best practice is to return concrete types.
Also, `err` is just an example in this minimal snippet. It can happen with any variable.
Here's a similar snippet: https://play.golang.org/p/WKPey_PL_ht https://play.golang.org/p/WKPey_PL_ht -- Looks impossible to crash. :P
Spoiler: it's a boxed null, not a null.
- thegeekpirate 8y ago> But best practice is to return concrete types. You're taking this as an absolute when you shouldn't be. There's plenty of places in the standard library that don't follow this "rule".
- deleted 8y ago[deleted]
- chrsm 8y agoBest practice is to return concrete types for everything, but error is one of those "special" cases that people tend to return an `error` for, IME. You can always unwrap it via type assertion, however ugly that may be.
- skj 8y ago> But best practice is to return concrete types. Except for errors. Use the `error` interface.