Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move from standard errors to xerrors #2259

Open
tharvik opened this issue Apr 30, 2020 · 9 comments
Open

move from standard errors to xerrors #2259

tharvik opened this issue Apr 30, 2020 · 9 comments

Comments

@tharvik
Copy link
Contributor

tharvik commented Apr 30, 2020

Even though go 1.13 included some new features into the standard errors package, the trace feature available in xerrors is not there.

For this reason all errors.New messages should be replaced with xerrors.New messages.

@ineiti
Copy link
Member

ineiti commented Aug 24, 2020

In fact we need to do the inverse: only xerrors.New and xerrors.Errorf allow to have the error-stack included...

@tharvik
Copy link
Contributor Author

tharvik commented Aug 24, 2020

FYI, there is also https://github.com/JavierZunzunegui/zerrors which is stable, see discussion on golang.

@nkcr
Copy link
Contributor

nkcr commented Aug 24, 2020

I also stumbled upon this one: https://github.com/cockroachdb/errors

@ineiti
Copy link
Member

ineiti commented Aug 24, 2020

Oh my - they grow like the ulcers in my stomach when I work on typescript!

  • xerrors - works so far, even if I'm not a big fan of how it prints the frame
  • zerrors - new kid on the block - no changes in the last 6 months, method-names seem to mix Wrap with the frame
  • errors - has it all, but might be overkill - also I don't like the namespace clashing with the go errors

Please add your vote:

@ineiti ineiti changed the title move from xerrors to standard errors/fmt move from standard errors to xerrors Sep 2, 2020
@ineiti
Copy link
Member

ineiti commented Sep 2, 2020

@tharvik why errors? Don't you like the trace feature of xerrors to know where it all happened?

@tharvik
Copy link
Contributor Author

tharvik commented Sep 2, 2020

@tharvik why errors? Don't you like the trace feature of xerrors to know where it all happened?

I meant the errors from https://github.com/cockroachdb/errors

But yeah, I prefer the basic golang's errors. I think we can quite precisely know where an error happened just by looking at the resulting string. Each time a check for error is done, a context is added using fmt.Errorf, which is way more readable than a full stacktrace.

@ineiti
Copy link
Member

ineiti commented Sep 3, 2020

which is way more readable than a full stacktrace.

Hmm - when debugging, I like having a list of methods and files where the error got passed up to. It helps me to faster dig into where the problem might actually be happening. If I just have the context, a la:

context 1: context 2: context 3: context 4: actual error

I first have to search for each context, decide if it's actually a problem, and then move on. If I have

file1: method1: line1: context 1
file2: method2: line2: context2
file3: method3: line3: context3
file4: method4: line4: actual error

I can directly scan the methods and decide where to jump in...

@tharvik
Copy link
Contributor Author

tharvik commented Sep 3, 2020

context 1: context 2: context 3: context 4: actual error

I first have to search for each context, decide if it's actually a problem, and then move on.

Then the contextes aren't helpful/detailed/relevant enough :P

That's mostly a matter of taste IMO, it is a small preference for me, so, your call :)

@nkcr
Copy link
Contributor

nkcr commented Sep 3, 2020

Then the contextes aren't helpful/detailed/relevant enough :P

Just to add my grain of salt, this is exactly what I think and said back then when we choose to move to xerrors. If your context is well written (ie. never do a return nil, err and always use a nice wrapping message), then you should have no problem seeing where the error happened.
But since we changed, my opinion is we should stick to that for the moment.

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

No branches or pull requests

4 participants
@ineiti @nkcr @tharvik and others