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.
In Go 1.26, there was a new pattern for error type comparison introduced (docs):
Sometimes, we care only about error type, so there is no need to have an extra variable:
In this case,
errcheckwill 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-functionsdoesn't respecterrors.AsType/errors.AsType(err error). So, I guess, some code modifications in the linter itself are needed.