pkg / errors

Simple error handling primitives
https://godoc.org/github.com/pkg/errors
BSD 2-Clause "Simplified" License
8.2k stars 697 forks source link

[question] Is there a way to get msg from errors.Wrap(code, msg)? #164

Open allencloud opened 6 years ago

allencloud commented 6 years ago

Hi, I have a question for the project.

Now there is a line of code :

func A() error{
     return errors.Wrap(code, msg)
}

Then I have a caller err := A(), so can I use the returned err to get msg?

Thanks in advance.

davecheney commented 6 years ago

Not really. This was a deliberate choice to avoid using the string form of an error to transmit context between locations in the call stack

On 2 Aug 2018, at 02:38, Allen Sun notifications@github.com wrote:

Hi, I have a question for the project.

Now there is a line of code :

func A() error{ return errors.Wrap(code, msg) } Then I have a caller err := A(), so can I use the returned err to get msg?

Thanks in advance.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

gumingqi commented 5 years ago

I want to set error code,and use it in the caller too