That's because the `Error` method is declared on the pointer, not the
value. So `fmt` uses its reflect-based printing for structs.

On Sun, Sep 19, 2021 at 1:44 PM Brian Candler <b.cand...@pobox.com> wrote:

> However, the zero value itself is printable.  It's only a pointer to the
> zero value which panics.
> https://play.golang.org/p/LhmhdeHTb0m
>
> On Sunday, 19 September 2021 at 12:34:40 UTC+1 axel.wa...@googlemail.com
> wrote:
>
>> I don't know if it's intentional, but I think it's expected. The panic
>> happens because it tries to stringify the underlying error, which is nil. I
>> would say the creation of a packages error types are the purview of that
>> package. I don't think you can, generally, expect that their zero values
>> are valid.
>>
>> On Sun, Sep 19, 2021 at 1:29 PM Brian Candler <b.ca...@pobox.com> wrote:
>>
>>> Is this intentional?
>>> https://play.golang.org/p/ylXlkOq2sID
>>>
>>> Result I get in browser:
>>>
>>> &{0}
>>> %!v(PANIC=Error method: runtime error: invalid memory address or nil
>>> pointer dereference)
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/73b364e9-bb46-4ec6-9d3d-42e7b04772f5n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/golang-nuts/73b364e9-bb46-4ec6-9d3d-42e7b04772f5n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/a2ea19c3-cc2a-4265-8c24-9b79ea037dbbn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/a2ea19c3-cc2a-4265-8c24-9b79ea037dbbn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfFgNq5c7RRHHgn32CVKprfF6Kke7u5G3ONR8Tt_%3DN0HUg%40mail.gmail.com.

Reply via email to