Skip to content

errors: feature request: nil-safe compares #6965

@happygiraffe

Description

@happygiraffe
Frequently when writing tests, we end up comparing two error values, on of which may be
nil.  It would be useful to have an errors.Equal() function, which can execute a
nil-safe comparison.  This is the function, which we've been copy-and-pasting around our
test packages:

func Equal(a, b error) bool {
    if a == nil {
        return b == nil
    }
    return b != nil && a.Error() == b.Error()
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions