protect against prevPath nil panic (#2000)
## Description Return an error if a collection in a deleted state has a nil previousPath. This technically should never occur, but we'll prefer an error over a panic. ## Does this PR need a docs update or release note? - [x] ⛔ No ## Type of change - [x] 🐛 Bugfix ## Issue(s) * #1999 ## Test Plan - [x] 💚 E2E
This commit is contained in:
parent
ad691148fe
commit
37b9eab2a7
@ -36,7 +36,7 @@ type Collection interface {
|
|||||||
FullPath() path.Path
|
FullPath() path.Path
|
||||||
// PreviousPath returns the path.Path this collection used to reside at
|
// PreviousPath returns the path.Path this collection used to reside at
|
||||||
// (according to the M365 ID for the container) if the collection was moved or
|
// (according to the M365 ID for the container) if the collection was moved or
|
||||||
// renamed. Returns nil if the collection is new or has been deleted.
|
// renamed. Returns nil if the collection is new.
|
||||||
PreviousPath() path.Path
|
PreviousPath() path.Path
|
||||||
// State represents changes to the Collection compared to the last backup
|
// State represents changes to the Collection compared to the last backup
|
||||||
// involving the Collection. State changes are based on the M365 ID of the
|
// involving the Collection. State changes are based on the M365 ID of the
|
||||||
|
|||||||
@ -583,13 +583,16 @@ func inflateCollectionTree(
|
|||||||
for _, s := range collections {
|
for _, s := range collections {
|
||||||
switch s.State() {
|
switch s.State() {
|
||||||
case data.DeletedState:
|
case data.DeletedState:
|
||||||
|
if s.PreviousPath() == nil {
|
||||||
|
return nil, nil, errors.Errorf("nil previous path on deleted collection")
|
||||||
|
}
|
||||||
|
|
||||||
changedPaths = append(changedPaths, s.PreviousPath())
|
changedPaths = append(changedPaths, s.PreviousPath())
|
||||||
|
|
||||||
if _, ok := updatedPaths[s.PreviousPath().String()]; ok {
|
if _, ok := updatedPaths[s.PreviousPath().String()]; ok {
|
||||||
return nil, nil, errors.Errorf(
|
return nil, nil, errors.Errorf(
|
||||||
"multiple previous state changes to collection %s",
|
"multiple previous state changes to collection %s",
|
||||||
s.PreviousPath(),
|
s.PreviousPath())
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedPaths[s.PreviousPath().String()] = nil
|
updatedPaths[s.PreviousPath().String()] = nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user