2 Copyright 2017 The Kubernetes Authors.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
26 ErrBadJSONDoc = errors.New("invalid JSON document")
27 ErrNoListOfLists = errors.New("lists of lists are not supported")
28 ErrBadPatchFormatForPrimitiveList = errors.New("invalid patch format of primitive list")
29 ErrBadPatchFormatForRetainKeys = errors.New("invalid patch format of retainKeys")
30 ErrBadPatchFormatForSetElementOrderList = errors.New("invalid patch format of setElementOrder list")
31 ErrPatchContentNotMatchRetainKeys = errors.New("patch content doesn't match retainKeys list")
32 ErrUnsupportedStrategicMergePatchFormat = errors.New("strategic merge patch format is not supported")
35 func ErrNoMergeKey(m map[string]interface{}, k string) error {
36 return fmt.Errorf("map: %v does not contain declared merge key: %s", m, k)
39 func ErrBadArgType(expected, actual interface{}) error {
40 return fmt.Errorf("expected a %s, but received a %s",
41 reflect.TypeOf(expected),
42 reflect.TypeOf(actual))
45 func ErrBadArgKind(expected, actual interface{}) error {
46 var expectedKindString, actualKindString string
48 expectedKindString = "nil"
50 expectedKindString = reflect.TypeOf(expected).Kind().String()
53 actualKindString = "nil"
55 actualKindString = reflect.TypeOf(actual).Kind().String()
57 return fmt.Errorf("expected a %s, but received a %s", expectedKindString, actualKindString)
60 func ErrBadPatchType(t interface{}, m map[string]interface{}) error {
61 return fmt.Errorf("unknown patch type: %s in map: %v", t, m)
64 // IsPreconditionFailed returns true if the provided error indicates
65 // a precondition failed.
66 func IsPreconditionFailed(err error) bool {
67 _, ok := err.(ErrPreconditionFailed)
71 type ErrPreconditionFailed struct {
75 func NewErrPreconditionFailed(target map[string]interface{}) ErrPreconditionFailed {
76 s := fmt.Sprintf("precondition failed for: %v", target)
77 return ErrPreconditionFailed{s}
80 func (err ErrPreconditionFailed) Error() string {
84 type ErrConflict struct {
88 func NewErrConflict(patch, current string) ErrConflict {
89 s := fmt.Sprintf("patch:\n%s\nconflicts with changes made from original to current:\n%s\n", patch, current)
93 func (err ErrConflict) Error() string {
97 // IsConflict returns true if the provided error indicates
98 // a conflict between the patch and the current configuration.
99 func IsConflict(err error) bool {
100 _, ok := err.(ErrConflict)