Skip to content

Add support for ignoring errors.AsType error return value checks #274

@weisdd

Description

@weisdd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions