mirror of
https://github.com/restic/restic.git
synced 2024-12-21 23:33:03 +00:00
errors, fs: Replace CombineErrors with stdlib Join
This does not produce exactly the same messages, as it inserts newlines instead of "; ". But given how long our error messages can be, that might be a good thing.
This commit is contained in:
parent
19653f9e06
commit
2b609d3e77
3 changed files with 4 additions and 29 deletions
|
@ -2,7 +2,6 @@ package errors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stderrors "errors"
|
stderrors "errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -36,35 +35,11 @@ func As(err error, tgt interface{}) bool { return stderrors.As(err, tgt) }
|
||||||
// Is reports whether any error in err's tree matches target.
|
// Is reports whether any error in err's tree matches target.
|
||||||
func Is(x, y error) bool { return stderrors.Is(x, y) }
|
func Is(x, y error) bool { return stderrors.Is(x, y) }
|
||||||
|
|
||||||
|
func Join(errs ...error) error { return stderrors.Join(errs...) }
|
||||||
|
|
||||||
// Unwrap returns the result of calling the Unwrap method on err, if err's type contains
|
// Unwrap returns the result of calling the Unwrap method on err, if err's type contains
|
||||||
// an Unwrap method returning error. Otherwise, Unwrap returns nil.
|
// an Unwrap method returning error. Otherwise, Unwrap returns nil.
|
||||||
//
|
//
|
||||||
// Unwrap only calls a method of the form "Unwrap() error". In particular Unwrap does not
|
// Unwrap only calls a method of the form "Unwrap() error". In particular Unwrap does not
|
||||||
// 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 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
|
|
||||||
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 += errVal.Error()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if combinedErrorMsg == "" {
|
|
||||||
return nil // If no errors, return nil
|
|
||||||
} else if !multipleErrors {
|
|
||||||
return err // If only one error, return that first error
|
|
||||||
}
|
|
||||||
return fmt.Errorf("multiple errors occurred: [%s]", combinedErrorMsg)
|
|
||||||
}
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ func nodeFillExtra(node *restic.Node, path string, fi os.FileInfo, ignoreXattrLi
|
||||||
allowExtended, err := nodeFillGenericAttributes(node, path, &stat)
|
allowExtended, err := nodeFillGenericAttributes(node, path, &stat)
|
||||||
if allowExtended {
|
if allowExtended {
|
||||||
// Skip processing ExtendedAttributes if allowExtended is false.
|
// Skip processing ExtendedAttributes if allowExtended is false.
|
||||||
err = errors.CombineErrors(err, nodeFillExtendedAttributes(node, path, ignoreXattrListError))
|
err = errors.Join(err, nodeFillExtendedAttributes(node, path, ignoreXattrListError))
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,7 @@ func nodeRestoreGenericAttributes(node *restic.Node, path string, warn func(msg
|
||||||
}
|
}
|
||||||
|
|
||||||
restic.HandleUnknownGenericAttributesFound(unknownAttribs, warn)
|
restic.HandleUnknownGenericAttributesFound(unknownAttribs, warn)
|
||||||
return errors.CombineErrors(errs...)
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// genericAttributesToWindowsAttrs converts the generic attributes map to a WindowsAttributes and also returns a string of unknown attributes that it could not convert.
|
// genericAttributesToWindowsAttrs converts the generic attributes map to a WindowsAttributes and also returns a string of unknown attributes that it could not convert.
|
||||||
|
|
Loading…
Reference in a new issue