mirror of
https://github.com/Jguer/yay
synced 2024-09-06 16:43:03 +00:00
Steal multierror from aurlib
This commit is contained in:
parent
6b25e60f8b
commit
58240bdc3d
34
utils.go
34
utils.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
|
@ -128,3 +129,36 @@ func removeInvalidTargets(targets []string) []string {
|
|||
|
||||
return filteredTargets
|
||||
}
|
||||
|
||||
type MultiError struct {
|
||||
Errors []error
|
||||
mux sync.Mutex
|
||||
}
|
||||
|
||||
func (err *MultiError) Error() string {
|
||||
str := ""
|
||||
|
||||
for _, e := range err.Errors {
|
||||
str += e.Error()
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
func (err *MultiError) Add(e error) {
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
|
||||
err.mux.Lock()
|
||||
err.Errors = append(err.Errors, e)
|
||||
err.mux.Unlock()
|
||||
}
|
||||
|
||||
func (err *MultiError) Return() error {
|
||||
if len(err.Errors) > 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue