If I’m creating an error like
fmt.Errorf("%s must be foo, got %s", bar, baz), is there a way to test equality without comparing the string value?
StatusTeapotand then we use its URL as the argument to
DumbGetterso we can see it handles non
How would I want to use this code?
DumbGetteris provide a way for users to use the type system to understand what kind of error has happened.
DumbGettercould return us something like
BadStatusErrorimplement the error interface.
BadStatusError. This reflects our desire for the kind of error clearer. Assuming the assertion passes we can then check the properties of the error are correct.
DumbGetterby updating our error handling code to use our type
DumbGetterfunction has become simpler, it's no longer concerned with the intricacies of an error string, it just creates a
error, so if they choose to they can pass it up the call stack or log it like any other