-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
use const for custom error type #22
Comments
The idea of
A usability issue of this is that if we do
(https://play.golang.org/p/V2Gyd1mVkb9) Admittedly, this isn't terribly inconvenient because most of the time we'll do Also, to keep the exported API surface small, we'll likely want to use an
I dislike the idea of exporting an entity with a type that is not meant to be I think we should chew on this a bit and weigh the usability and hygiene |
type Error string
const ErrCouldNotOpen = Error("could not open") does not have func f() error {
return ErrCouldNotOpen
} won't compile (with func (e Error) Error() string {
panic("implement me")
} is added, which I personally think becomes a little bit too much code for a general case. Something else to consider: if -1 from me on |
Agree with @abhinav, given the trade-offs, I don't think this is something we should do right now. |
FWIW, here's a simpler approach that opens the door to "effectively constant" sentinel error values: var errCouldNotOpen = errors.New("could not open")
func ErrCouldNotOpen() error {
return errCouldNotOpen
} When you think about it, this is essentially what |
I am more in favor of @davecheney 's constant-errors than using var.
is better than
The text was updated successfully, but these errors were encountered: