-
-
Notifications
You must be signed in to change notification settings - Fork 657
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
Rework errors concepts and exercise #2666
Conversation
concepts/errors/about.md
Outdated
|
||
You do not have to always implement the error interface yourself. | ||
To create a simple error, you can use the `errors.New()` function that is part of the standard library package `errors`. | ||
The only thing you need to pass in is the error message as a string. |
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.
The only thing you need to pass in is the error message as a string. | |
The only thing you need to pass in is the error message as a string, and `errors.New()` will take care of creating a value that implements the `error` interface for you, containing the error message provided. |
Added this to clarify that there's nothing magical about errors.New()
and that is more of a utility function rather than a special way to create errors.
Feel free to reword or change sentences around.
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.
Good point, I reworded it a bit and applied it in all the places.
By convention, the error message should start with a lowercase letter and not end with a period. | ||
|
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.
Should we include an example of a good message vs a bad one, or do you think one can easily pick this by the other examples in the text?
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 don't think this bit is important enough that we need those examples right now. If someone starts their error messages with uppercase in their real code, so be it, no harm is done as long as they have meaningful messages.
Next part of #2492