errors icon indicating copy to clipboard operation
errors copied to clipboard

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

Open allencloud opened this issue 7 years ago • 2 comments

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.

allencloud avatar Aug 01 '18 16:08 allencloud

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 [email protected] 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.

davecheney avatar Aug 01 '18 23:08 davecheney

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

gumingqi avatar Jul 29 '19 13:07 gumingqi