-
Notifications
You must be signed in to change notification settings - Fork 141
Add support for ignoring errors.AsType error return value checks #274
Copy link
Copy link
Open
Description
In Go 1.26, there was a new pattern for error type comparison introduced (docs):
if _, err := os.Open("non-existing"); err != nil {
if pathError, ok := errors.AsType[*fs.PathError](err); ok {
fmt.Println("Failed at path:", pathError.Path)
} else {
fmt.Println(err)
}
}Sometimes, we care only about error type, so there is no need to have an extra variable:
if _, ok := errors.AsType[*folders.DeleteFolderNotFound](err); !ok {
return err
}In this case, errcheck will emit the "Error return value is not checked" error.
Adding "nolint" comments everywhere (for golangci-lint) is a bit burdensome, and it appears that exclude-functions doesn't respect errors.AsType / errors.AsType(err error). So, I guess, some code modifications in the linter itself are needed.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels