Re: Pointer Receivers on Error() and String() methods

2015-08-24 Thread roger peppe
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() (

Re: Pointer Receivers on Error() and String() methods

2015-08-24 Thread Nate Finch
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

Re: Pointer Receivers on Error() and String() methods

2015-08-24 Thread David Cheney
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)

Re: Pointer Receivers on Error() and String() methods

2015-08-24 Thread roger peppe
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

Pointer Receivers on Error() and String() methods

2015-08-19 Thread Nate Finch
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