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

Consider go1.13 errors package #414

Closed
ahmetb opened this issue Dec 1, 2019 · 18 comments
Closed

Consider go1.13 errors package #414

ahmetb opened this issue Dec 1, 2019 · 18 comments
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. priority/P3 P3 issues or PRs

Comments

@ahmetb
Copy link
Member

ahmetb commented Dec 1, 2019

Go has introduced new error wrapping primitives. Especially the errors.Is check can be useful to krew in certain few locations that we rely on error type (ENOENT etc).

https://golang.org/doc/go1.13#error_wrapping

@ahmetb ahmetb added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. priority/P3 P3 issues or PRs good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. labels Dec 1, 2019
@corneliusweig
Copy link
Contributor

corneliusweig commented Dec 1, 2019

Before doing this, we should think about what implementation details due to the errors API we want to make public (the blog post has more details on this topic).

Also, https://github.com/fatih/errwrap might be helpful.

@erain
Copy link

erain commented Dec 3, 2019

/assign I can help with this.

@erain
Copy link

erain commented Dec 3, 2019

For reference, the blog post @corneliusweig mentioned is https://blog.golang.org/go1.13-errors

@ahmetb
Copy link
Member Author

ahmetb commented Dec 3, 2019

Thanks. It would be good to see if we get Stack Traces like the current err pkg when run with -v 5 etc

@corneliusweig
Copy link
Contributor

Thanks @erain. I got confused and thought that the link from @.ahmetb was the same 🤦‍♂️

@ferhatelmas
Copy link
Contributor

Also, fatih/errwrap might be helpful.

I offered help to integrate errwrap into golangci-lint. It have it locally, will push upstream accordingly.

@corneliusweig
Copy link
Contributor

@ferhatelmas would that make sense? My understanding is that it should be a deliberate choice to wrap or not to wrap (see blog.golang.org/go1.13-errors). A linter would simply report any such occurrence.

@ferhatelmas
Copy link
Contributor

I think yes because even if it's decided to wrap, people are error-prone and might forget putting %w and might use %s or %q.

Also, it helps in transition with --fix flag of golangci-lint to automatically refactor codebase.

@corneliusweig
Copy link
Contributor

But if I understand correctly, the decision to wrap or not is done on a case-by-case basis, right?

@ferhatelmas
Copy link
Contributor

Yes. Here is a reply to it from the famous blog post.

When adding additional context to an error, either with fmt.Errorf or by implementing a custom type, you need to decide whether the new error should wrap the original. There is no single answer to this question; it depends on the context in which the new error is created.

That's why it should be opt-in linter, false by default.

@ahmetb
Copy link
Member Author

ahmetb commented Dec 4, 2019

Here's the criteria I expect from this new errors mechanism:

  • ability to wrap errors (to add more context/reason) without having to implement a custom type
  • preserves syntax while printing the wrapped error messages (reason: reason: root cause)
  • preserves ability to print errors normally (as above) or with stack trace when -v≥1 specified (currently achieved wit %+v)
  • ability to assess if one of the errors in the wrapped chain is of a certain error instance (e.g. io.EOF) or can be evaluated with methods like os.IsNotExist()

@ahmetb
Copy link
Member Author

ahmetb commented Dec 25, 2019

Promising new library: https://github.com/rotisserie/eris not sure if compatible with go1.13 errors but seems to have the same capabilities and nearly identical interface.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 25, 2020
@erain
Copy link

erain commented Mar 25, 2020

/unassign @erain

I am really sorry but I don't have the bandwidth for working on this now.

@corneliusweig
Copy link
Contributor

ping @robertvolkmann. You expressed some interest in this a while back, I think.

@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Apr 24, 2020
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. priority/P3 P3 issues or PRs
Projects
None yet
Development

No branches or pull requests

6 participants