Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Question: Obtaining the original cause #138

Open
johngb opened this issue Oct 10, 2017 · 5 comments
Open

Question: Obtaining the original cause #138

johngb opened this issue Oct 10, 2017 · 5 comments

Comments

@johngb
Copy link

johngb commented Oct 10, 2017

I have been using this package for a while now without any problems (I love it). However, today I came across a behaviour in my code that I can't understand when trying compare the result of errors.Cause with a named error. I've read through the documentation, and I came across the following statement:

Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection.

  1. In which situations is it necessary to reverse the operation of errors.Wrap to inspect the original error?
  2. How does one reverse the operation of errors.Wrap to obtain the original error?
@pierrre
Copy link

pierrre commented Oct 14, 2017

How does one reverse the operation of errors.Wrap to obtain the original error?

https://github.com/pkg/errors#retrieving-the-cause-of-an-error

@johngb
Copy link
Author

johngb commented Oct 14, 2017

@pierrre I asked because I had a case where errors.Cause was returning an error which when compared to the original named error in a package did not evaluate as equal.

We've subsequently worked around the issue by comparing the err.Error() string for each instead, but the problem was perplexing.

@pierrre
Copy link

pierrre commented Oct 15, 2017

where errors.Cause was returning an error which when compared to the original named error in a package did not evaluate as equal

Why aren't they equal ?
Did you inspect the error values with fmt.Printf("%#v", err) ?

@johngb
Copy link
Author

johngb commented Oct 15, 2017

Why aren't they equal ?

I wish I knew. From everything that I understand, they should be, but for some unknown reason weren't evaluating as equal.

Did you inspect the error values with fmt.Printf("%#v", err) ?

No, I didn't, but in hindsight I should have. For logistical reasons it may not be feasible for me to roll back the project to test this out, but I'll do my best to compare them this week.

@LasTshaMAN
Copy link

@johngb Any followup on this ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants