Mirantis / hmc

Apache License 2.0
17 stars 16 forks source link

Erroneous usage of `errors.Join` function #258

Closed zerospiel closed 2 months ago

zerospiel commented 2 months ago

In the codebase, there are multiple entries (e.g. one, two, three) of wrong errors.Join function usage leading to the non-expected results.

In the following example one could clearly see the problem:

func main() {
    var merr error
    for i := range 3 {
        merr = errors.Join(fmt.Errorf("%d", i))
    }
    fmt.Printf("incorrect multi-error: %v\n", merr)
    merr = nil
    for i := range 3 {
        merr = errors.Join(merr, fmt.Errorf("%d", i))
    }
    fmt.Printf("correct multi-error: %v\n", merr)
}

The output is:

incorrect multi-error: 2
correct multi-error: 0
1
2