Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Remove dependency on go.uber.org/multierr
- Loading branch information
Showing
15 changed files
with
118 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Package chezmoierrors contains convenience functions for combining multiple | ||
// errors. | ||
package chezmoierrors | ||
|
||
import "errors" | ||
|
||
// Combine combines all non-nil errors in errs into one. If there are no non-nil | ||
// errors, it returns nil. If there is exactly one non-nil error then it returns | ||
// that error. Otherwise, it returns the non-nil errors combined with | ||
// errors.Join. | ||
func Combine(errs ...error) error { | ||
nonNilErrs := make([]error, 0, len(errs)) | ||
for _, err := range errs { | ||
if err != nil { | ||
nonNilErrs = append(nonNilErrs, err) | ||
} | ||
} | ||
switch len(nonNilErrs) { | ||
case 0: | ||
return nil | ||
case 1: | ||
return nonNilErrs[0] | ||
default: | ||
return errors.Join(nonNilErrs...) | ||
} | ||
} | ||
|
||
// CombineClose combines the error pointed to by errp with the result of calling | ||
// closer.Close(). | ||
func CombineClose(errp *error, closer interface{ Close() error }) { | ||
CombineFunc(errp, closer.Close) | ||
} | ||
|
||
// CombineFunc combines the error pointed to by errp with the result of calling | ||
// f. | ||
func CombineFunc(errp *error, f func() error) { | ||
if err := f(); err != nil { | ||
*errp = Combine(*errp, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.