-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add wrapping errors #517
Conversation
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).
65b03ae
to
62da17f
Compare
There was a problem hiding this 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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I elaborated the comment.
There was a problem hiding this 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
This PR add sentinel errors and wrapping errors.
Fixes #334