|
1 | 1 | package resourcemodifiers |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "errors" |
4 | 5 | "fmt" |
5 | 6 | "net/http" |
6 | 7 |
|
@@ -37,7 +38,7 @@ func (p *StrategicMergePatcher) Patch(u *unstructured.Unstructured, _ logrus.Fie |
37 | 38 | for _, patch := range p.patches { |
38 | 39 | patchBytes, err := yaml.YAMLToJSON([]byte(patch.PatchData)) |
39 | 40 | if err != nil { |
40 | | - return nil, fmt.Errorf("error in converting YAML to JSON %s", err) |
| 41 | + return nil, fmt.Errorf("error in converting YAML to JSON %w", err) |
41 | 42 | } |
42 | 43 |
|
43 | 44 | err = strategicPatchObject(origin, patchBytes, updated, schemaReferenceObj) |
@@ -127,10 +128,15 @@ func applyPatchToObject( |
127 | 128 |
|
128 | 129 | // interpretStrategicMergePatchError interprets the error type and returns an error with appropriate HTTP code. |
129 | 130 | func interpretStrategicMergePatchError(err error) error { |
130 | | - switch err { |
131 | | - case mergepatch.ErrBadJSONDoc, mergepatch.ErrBadPatchFormatForPrimitiveList, mergepatch.ErrBadPatchFormatForRetainKeys, mergepatch.ErrBadPatchFormatForSetElementOrderList, mergepatch.ErrUnsupportedStrategicMergePatchFormat: |
| 131 | + switch { |
| 132 | + case errors.Is(err, mergepatch.ErrBadJSONDoc), |
| 133 | + errors.Is(err, mergepatch.ErrBadPatchFormatForPrimitiveList), |
| 134 | + errors.Is(err, mergepatch.ErrBadPatchFormatForRetainKeys), |
| 135 | + errors.Is(err, mergepatch.ErrBadPatchFormatForSetElementOrderList), |
| 136 | + errors.Is(err, mergepatch.ErrUnsupportedStrategicMergePatchFormat): |
132 | 137 | return apierrors.NewBadRequest(err.Error()) |
133 | | - case mergepatch.ErrNoListOfLists, mergepatch.ErrPatchContentNotMatchRetainKeys: |
| 138 | + case errors.Is(err, mergepatch.ErrNoListOfLists), |
| 139 | + errors.Is(err, mergepatch.ErrPatchContentNotMatchRetainKeys): |
134 | 140 | return apierrors.NewGenericServerResponse(http.StatusUnprocessableEntity, "", schema.GroupResource{}, "", err.Error(), 0, false) |
135 | 141 | default: |
136 | 142 | return err |
|
0 commit comments