You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The stdlib error wrapping capability via fmt + %w allows for error wrapping as defined in the Go 2 error wrapping spec (citation needed) and as understood by the third-party errors package (and probably many others). The work to be done is:
define a const-ish "base" error type for errors that originate in this package
replace all runtime generated errors (errors.New) with error wrapping via fmt + %w
The text was updated successfully, but these errors were encountered:
Errors have become better in go and defining all errors as either a variable or a concrete type that satisfies the error interface is the way to properly deal with errors.
var (
ErrInvalidSyntax=errors.New("invalid syntax")
)
Even if all errors aren't going to be used in error comparisons by the users of this package, having a consistent way of defining errors to allow the use of the facilities provided by the errors package is going to help in the long run and maintainability. So avoiding the use of errors.New inside functions and fmt.Errorf without the use of wrapping (verb %w) will make the overall experience with dealing with this package better.
I don't agree with having one base error but having a few errors that cover larger areas where more information can be provided via fields in the error type or wrapped using fmt.Errorf is a good approach. The names of the errors or error types should be easily understood so having one to rule them all is not a good approach.
The stdlib error wrapping capability via
fmt
+%w
allows for error wrapping as defined in the Go 2 error wrapping spec (citation needed) and as understood by the third-party errors package (and probably many others). The work to be done is:errors.New
) with error wrapping viafmt
+%w
The text was updated successfully, but these errors were encountered: