mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Detect a missing key error and print a cleaner message.
This commit is contained in:
parent
de8cc31355
commit
e3d2242388
@ -306,7 +306,15 @@ func getPatchedJSON(patchType types.PatchType, originalJS, patchJS []byte, gvk s
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return patchObj.Apply(originalJS)
|
||||
bytes, err := patchObj.Apply(originalJS)
|
||||
// TODO: This is pretty hacky, we need a better structured error from the json-patch
|
||||
if err != nil && strings.Contains(err.Error(), "doc is missing key") {
|
||||
msg := err.Error()
|
||||
ix := strings.Index(msg, "key:")
|
||||
key := msg[ix+5:]
|
||||
return bytes, fmt.Errorf("Object to be patched is missing field (%s)", key)
|
||||
}
|
||||
return bytes, err
|
||||
|
||||
case types.MergePatchType:
|
||||
return jsonpatch.MergePatch(originalJS, patchJS)
|
||||
|
Loading…
Reference in New Issue
Block a user