add clues, fault to op/restore.go (#2320)
## Does this PR need a docs update or release note? - [x] ⛔ No ## Type of change - [x] 🧹 Tech Debt/Cleanup ## Issue(s) * #1970 ## Test Plan - [x] ⚡ Unit test
This commit is contained in:
parent
b3b5189e19
commit
63ffd8004a
@ -25,6 +25,7 @@ import (
|
||||
"github.com/alcionai/corso/src/pkg/account"
|
||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||
"github.com/alcionai/corso/src/pkg/control"
|
||||
"github.com/alcionai/corso/src/pkg/fault"
|
||||
"github.com/alcionai/corso/src/pkg/logger"
|
||||
"github.com/alcionai/corso/src/pkg/path"
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
@ -201,7 +202,7 @@ func (op *RestoreOperation) do(
|
||||
return nil, errors.Wrap(err, "getting backup and details")
|
||||
}
|
||||
|
||||
paths, err := formatDetailsForRestoration(ctx, op.Selectors, deets)
|
||||
paths, err := formatDetailsForRestoration(ctx, op.Selectors, deets, op.Errors)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "formatting paths from details")
|
||||
}
|
||||
@ -290,6 +291,7 @@ func (op *RestoreOperation) persistResults(
|
||||
if opStats.readErr != nil || opStats.writeErr != nil {
|
||||
op.Status = Failed
|
||||
|
||||
// TODO(keepers): replace with fault.Errors handling.
|
||||
return multierror.Append(
|
||||
errors.New("errors prevented the operation from processing"),
|
||||
opStats.readErr,
|
||||
@ -340,6 +342,7 @@ func formatDetailsForRestoration(
|
||||
ctx context.Context,
|
||||
sel selectors.Selector,
|
||||
deets *details.Details,
|
||||
errs *fault.Errors,
|
||||
) ([]path.Path, error) {
|
||||
fds, err := sel.Reduce(ctx, deets)
|
||||
if err != nil {
|
||||
@ -347,18 +350,21 @@ func formatDetailsForRestoration(
|
||||
}
|
||||
|
||||
var (
|
||||
errs *multierror.Error
|
||||
fdsPaths = fds.Paths()
|
||||
paths = make([]path.Path, len(fdsPaths))
|
||||
)
|
||||
|
||||
for i := range fdsPaths {
|
||||
if errs.Err() != nil {
|
||||
return nil, errs.Err()
|
||||
}
|
||||
|
||||
p, err := path.FromDataLayerPath(fdsPaths[i], true)
|
||||
if err != nil {
|
||||
errs = multierror.Append(
|
||||
errs,
|
||||
errors.Wrap(err, "parsing details entry path"),
|
||||
)
|
||||
errs.Add(clues.
|
||||
Wrap(err, "parsing details path after reduction").
|
||||
WithMap(clues.In(ctx)).
|
||||
With("path", fdsPaths[i]))
|
||||
|
||||
continue
|
||||
}
|
||||
@ -377,9 +383,5 @@ func formatDetailsForRestoration(
|
||||
return paths[i].String() < paths[j].String()
|
||||
})
|
||||
|
||||
if errs != nil {
|
||||
return nil, errs
|
||||
}
|
||||
|
||||
return paths, nil
|
||||
return paths, errs.Err()
|
||||
}
|
||||
|
||||
@ -285,6 +285,7 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run() {
|
||||
ds, err := ro.Run(ctx)
|
||||
|
||||
require.NoError(t, err, "restoreOp.Run()")
|
||||
require.Empty(t, ro.Errors.Errs(), "restoreOp.Run() recoverable errors")
|
||||
require.NotEmpty(t, ro.Results, "restoreOp results")
|
||||
require.NotNil(t, ds, "restored details")
|
||||
assert.Equal(t, ro.Status, Completed, "restoreOp status")
|
||||
|
||||
@ -13,5 +13,5 @@ func NewAdder() *Adder {
|
||||
|
||||
func (ma *Adder) Add(err error) *fault.Errors {
|
||||
ma.Errs = append(ma.Errs, err)
|
||||
return fault.New(false)
|
||||
return fault.New(true)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user