When making an example to reproduce a problem, I try to be as general as
possible.
The specific context of the question is a type that wraps multiple
errors. It implements the error interface. It's useful when individual
error handling is inconvenient, such as inside a defer block.
I ended up just adding a method which performs a simple if-else check
and returns an untyped nil if the interface refers to *ConcreteType(nil).
// me := NewMultiError(nil, nil, nil, nil)
// me == nil // true
// var err error = me
// err == me // true
// err == nil // false
// err = me.ToError()
// err == nil // true
func (m *MultiError) ToError() error {....}
In principle, it's ok to touch reflection in case any error is
encountered, because errors are not supposed to happen all the time. But
I try to avoid reflection when everything is nil.
Regardless, thank you everyone for the input. I learned something new.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.