From e3e59fef242ead47d2a227f88d73a7c638c4e9a5 Mon Sep 17 00:00:00 2001 From: Aneesh Nireshwalia <99904+aneesh-n@users.noreply.github.com> Date: Sat, 24 Feb 2024 13:22:34 -0700 Subject: [PATCH] Fix CombineErrors and fillExtendedAttr error handling --- internal/errors/errors.go | 27 +++++++++++++++++---------- internal/restic/node.go | 7 +------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/internal/errors/errors.go b/internal/errors/errors.go index 3c669f861..68a48b325 100644 --- a/internal/errors/errors.go +++ b/internal/errors/errors.go @@ -43,22 +43,29 @@ func Is(x, y error) bool { return stderrors.Is(x, y) } // unwrap errors returned by [Join]. func Unwrap(err error) error { return stderrors.Unwrap(err) } -// CombineErrors combines multiple errors into a single error. -func CombineErrors(errors ...error) error { +// CombineErrors combines multiple errors into a single error after filtering out any nil values. +// 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 - - for _, err := range errors { - if err != nil { + var multipleErrors bool + for _, errVal := range errors { + if errVal != nil { if combinedErrorMsg != "" { combinedErrorMsg += "; " // Separate error messages with a delimiter + multipleErrors = true + } else { + // Set the first error + err = errVal } - combinedErrorMsg += err.Error() + combinedErrorMsg += errVal.Error() } } - 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) } diff --git a/internal/restic/node.go b/internal/restic/node.go index cbe9ef363..8fc06df79 100644 --- a/internal/restic/node.go +++ b/internal/restic/node.go @@ -719,12 +719,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error { allowExtended, err := node.fillGenericAttributes(path, fi, stat) if allowExtended { // Skip processing ExtendedAttributes if allowExtended is false. - errEx := node.fillExtendedAttributes(path) - if err == nil { - err = errEx - } else { - debug.Log("Error filling extended attributes for %v at %v : %v", node.Name, path, errEx) - } + err = errors.CombineErrors(err, node.fillExtendedAttributes(path)) } return err }