forked from TrueCloudLab/restic
Fix CombineErrors and fillExtendedAttr error handling
This commit is contained in:
parent
09ce1b4e58
commit
e3e59fef24
2 changed files with 18 additions and 16 deletions
|
@ -43,22 +43,29 @@ func Is(x, y error) bool { return stderrors.Is(x, y) }
|
||||||
// unwrap errors returned by [Join].
|
// unwrap errors returned by [Join].
|
||||||
func Unwrap(err error) error { return stderrors.Unwrap(err) }
|
func Unwrap(err error) error { return stderrors.Unwrap(err) }
|
||||||
|
|
||||||
// CombineErrors combines multiple errors into a single error.
|
// CombineErrors combines multiple errors into a single error after filtering out any nil values.
|
||||||
func CombineErrors(errors ...error) error {
|
// If no errors are passed, it returns nil.
|
||||||
|
// If one error is passed, it simply returns that same error.
|
||||||
|
func CombineErrors(errors ...error) (err error) {
|
||||||
var combinedErrorMsg string
|
var combinedErrorMsg string
|
||||||
|
var multipleErrors bool
|
||||||
for _, err := range errors {
|
for _, errVal := range errors {
|
||||||
if err != nil {
|
if errVal != nil {
|
||||||
if combinedErrorMsg != "" {
|
if combinedErrorMsg != "" {
|
||||||
combinedErrorMsg += "; " // Separate error messages with a delimiter
|
combinedErrorMsg += "; " // Separate error messages with a delimiter
|
||||||
|
multipleErrors = true
|
||||||
|
} else {
|
||||||
|
// Set the first error
|
||||||
|
err = errVal
|
||||||
}
|
}
|
||||||
combinedErrorMsg += err.Error()
|
combinedErrorMsg += errVal.Error()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if combinedErrorMsg == "" {
|
if combinedErrorMsg == "" {
|
||||||
return nil // No errors, return nil
|
return nil // If no errors, return nil
|
||||||
|
} else if !multipleErrors {
|
||||||
|
return err // If only one error, return that first error
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("multiple errors occurred: [%s]", combinedErrorMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("multiple errors occurred: [%s]", combinedErrorMsg)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -719,12 +719,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
|
||||||
allowExtended, err := node.fillGenericAttributes(path, fi, stat)
|
allowExtended, err := node.fillGenericAttributes(path, fi, stat)
|
||||||
if allowExtended {
|
if allowExtended {
|
||||||
// Skip processing ExtendedAttributes if allowExtended is false.
|
// Skip processing ExtendedAttributes if allowExtended is false.
|
||||||
errEx := node.fillExtendedAttributes(path)
|
err = errors.CombineErrors(err, node.fillExtendedAttributes(path))
|
||||||
if err == nil {
|
|
||||||
err = errEx
|
|
||||||
} else {
|
|
||||||
debug.Log("Error filling extended attributes for %v at %v : %v", node.Name, path, errEx)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue