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

Add wrapping errors #517

Merged
merged 3 commits into from
Mar 21, 2024
Merged

Add wrapping errors #517

merged 3 commits into from
Mar 21, 2024

Conversation

guettli
Copy link
Contributor

@guettli guettli commented Mar 16, 2024

This PR add sentinel errors and wrapping errors.

Fixes #334

Before there was one page about error handling.

Now there are three.

A simple page (the first part of the existing page).

Then a new page about wrapping errors.

And the third page is the second half of the existing page (custom errors).
Copy link
Collaborator

@eliben eliben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the examples. I'm leaving some comments

"math/rand/v2"
)

// A "sentinel error" has usualy the prefix "Err"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a bit more explanation of what "sentinel error" is - as a stylistic convention

return ErrOutOfTea
}
if rand.Int32N(7) == 0 {
// You can wrap a sentinel error with %w
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can wrap any error...

if err != nil {
// By using several if-statements we can handle
// different sentinel errors.
// A switch statement is not applicable here.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't explain what Is does and how it's different from using a type switch, and why a type switch is not applicable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I elaborated the comment.

@guettli guettli requested a review from eliben March 20, 2024 19:11
Copy link
Collaborator

@eliben eliben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I will merge this and then will edit the examples a bit to save rounds of review back-and-forth

@eliben eliben merged commit cdb9266 into mmcgrana:master Mar 21, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Add Go 1.13 error handling to Error section
2 participants