[MINOR] Make composition of error and 'nil' return the original error
While working on adding missing error checks I noticed that calling err = errors.Compose(err, nil)
won't result in err
but instead [err]
.
That means we would need to search the codebase for hundreds of error check like err == ErrPeerExists
and change them to errors.Contains(err, ErrPeerExists)
since equality is broken by Compose
.
While possible, this is also risky cause missing a single check could be fatal. That's why I propose changing the problem at the root and adjust errors.Compose
to return the error directly if only a single non-nil error was provided.
This won't break errors.Contains
but guarantee that we don't accidentally break error checks by doing things like
defer func() {
err = errors.Compose(err, file.Close()) // results in [err] instead of err if file is closed successfully
}()
Edited by Christopher Schinnerl