Skip to content

proposal: cmd/vet: Not using the return value of a function that only produces an error should be flagged #72926

Closed as not planned
@rski

Description

@rski

Proposal Details

I ran into a piece of code today that did

if something {
   fmt.Errorf("something happened: %s", someString)
}

if somethingElse {
  return fmt.Errorf("something else happened: %s", someOtherString)
}

Clearly the first one was a mistake, the intention was to return. I think it would be nice if vet flagged such uses of Errorf, Wrapf, errors.New as they are most definitely not intentional.

There is an existing tool, https://github.com/kisielk/errcheck which would have pointed this out. However, in my experience integrating it in existing codebases can be quite tedious and requires fixing many calls that might be fishy but not necessarily buggy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions