return error for duplicate keys rather than panicking

This commit is contained in:
Natasha Sarkar
2021-03-03 12:03:36 -08:00
parent 93dd571df9
commit 722b0131f0
15 changed files with 86 additions and 31 deletions

View File

@@ -90,9 +90,14 @@ func (m *merginator) makeError(cd resource.ConflictDetector, index int) error {
if conflict == nil {
return fmt.Errorf("expected conflict for %s", m.incoming[index].OrgId())
}
conflictMap, _ := conflict.Map()
incomingIndexMap, _ := m.incoming[index].Map()
return fmt.Errorf(
"conflict between %#v at index %d and %#v",
m.incoming[index].Map(), index, conflict.Map())
incomingIndexMap,
index,
conflictMap,
)
}
// findConflict looks for a conflict in a resource slice.

View File

@@ -119,7 +119,11 @@ func (m *resWrangler) Debug(title string) {
fmt.Println("---")
}
fmt.Printf("# %d %s\n", i, r.OrgId())
blob, err := yaml.Marshal(r.Map())
m, err := r.Map()
if err != nil {
panic(err)
}
blob, err := yaml.Marshal(m)
if err != nil {
panic(err)
}
@@ -272,7 +276,8 @@ func (m *resWrangler) AsYaml() ([]byte, error) {
for _, res := range m.Resources() {
out, err := res.AsYAML()
if err != nil {
return nil, errors.Wrapf(err, "%#v", res.Map())
m, _ := res.Map()
return nil, errors.Wrapf(err, "%#v", m)
}
if firstObj {
firstObj = false
@@ -602,14 +607,23 @@ func (m *resWrangler) ApplySmPatch(
// Some unknown error, let it through.
return err
}
if !res.IsEmpty() {
empty, err := res.IsEmpty()
if err != nil {
return err
}
if !empty {
m, _ := res.Map()
return errors.Wrapf(
err, "with unexpectedly non-empty object map of size %d",
len(res.Map()))
len(m))
}
// Fall through to handle deleted object.
}
if !res.IsEmpty() {
empty, err := res.IsEmpty()
if err != nil {
return err
}
if !empty {
// IsEmpty means all fields have been removed from the object.
// This can happen if a patch required deletion of the
// entire resource (not just a part of it). This means