gt;> just return nil itself, instead of thinking it's a valid error and
>> >> wrapping
>> >> it.
>> >>
>> >> However, you can sidestep this entirely by doing one of two things:
>> >> either
>> >> just make the Error() (
d main.MyError.Error called using nil *MyError
> pointer)
> >>
> >> (you can try it with the repro code I linked to)
> >>
> >> This printout is a lot more helpful and useful and obvious than the
> other
> >> "nil pointer" printout.
&g
t;
>> (you can try it with the repro code I linked to)
>>
>> This printout is a lot more helpful and useful and obvious than the other
>> "nil pointer" printout.
>>
>> OR
>>
>> Just handle a nil receiver:
>>
>> func (e *MyError)
gt;
> (note that it is dereferencing the pointer to e to access the Message field
> which causes the panic. Calling a method on a nil pointer is totally fine
> and will not panic if the code inside does not try to derefence the pointer
> to get to a field).
>
> Grepping through our
tring {
if e == nil {
return ""
}
return e.Message
}
(note that it is dereferencing the pointer to e to access the Message field
which causes the panic. Calling a method on a nil pointer is totally fine
and will not panic if the code inside does not try to derefence the pointer