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
Currently, when using errors.As, one has to do some acrobatics to create a double pointer to the type of error they want to test. This usually leads to following constructs:
typeMyErrstruct{}
func (e*MyError) Error() string {return"foo"}
...varmyErr*MyErr// this is bloatiferrors.As(err, &myErr) {
...
}
Everytime one wants to use errors.As they have to first define a variable, and then use that variable. With AsTarget in place, this would be a bit simpler:
...
if errors.As(err, AsTarget(MyErr)) {
...
}
I'm very new to go, and I don't really understand the reasons why errors.As couldn't just accept a zero-instance of a type. But since it is what it is, would you consider adding AsTarget to the standard library?
The text was updated successfully, but these errors were encountered:
Proposal Details
Proposal details
Add following function to
errors
package:Rationale
Currently, when using
errors.As
, one has to do some acrobatics to create a double pointer to the type of error they want to test. This usually leads to following constructs:Everytime one wants to use
errors.As
they have to first define a variable, and then use that variable. WithAsTarget
in place, this would be a bit simpler:I'm very new to go, and I don't really understand the reasons why
errors.As
couldn't just accept a zero-instance of a type. But since it is what it is, would you consider addingAsTarget
to the standard library?The text was updated successfully, but these errors were encountered: