Skip to content

x/tools/go/analysis/passes/nilness: detect wrapping of nil errors #32808

@ainar-g

Description

@ainar-g

As of 4874f863, the nilness check doesn't seem to trigger on fmt.Errorf calls with an error that is proven nil. Example:

func f() error {
	exists, err := g()
	if err != nil {
		return errors.Wrap(err, "error1")
	}

	if !exists {
		return fmt.Errorf("nothing: %w", err)
	}

	return nil
}

Same with the %v verb. I feel like most people would not want to actually produce a nothing: <nil> or a nothing: %!w(<nil>) message here.

Inspired by dominikh/go-tools#529.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions