Skip to content

Suggest errors.New over fmt.Errorf with single string parameter and no formatting #1550

@Jacalz

Description

@Jacalz

I have seen a lot of code creating errors like fmt.Errorf("something went wrong") instead of errors.New("something went wrong"). Not only is the latter faster, but I also think that a lot of the former cases are wrong in subtle ways. If you use fmt.Errorf with a single string and no formatting verbs, you either forgot to add formatting (kind of related to #1528, I guess) or you should have used a regular error instead. As such, I think it be flagged as a problem and suggest replacing the call. In the case where you don't want to wrap or format anything, I also think it is a lot clearer to see a regular errors.New() as I can easily know that it is a static error string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionWe have to decide if this check is feasible and desirablenew-check

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions