github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/conversion/error.go (about) 1 /* 2 Copyright 2014 The Kubernetes Authors All rights reserved. 3 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 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 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. 15 */ 16 17 package conversion 18 19 import ( 20 "fmt" 21 "reflect" 22 ) 23 24 type notRegisteredErr struct { 25 kind string 26 version string 27 t reflect.Type 28 } 29 30 func (k *notRegisteredErr) Error() string { 31 if k.t != nil { 32 return fmt.Sprintf("no kind is registered for the type %v", k.t) 33 } 34 if len(k.kind) == 0 { 35 return fmt.Sprintf("no version %q has been registered", k.version) 36 } 37 if len(k.version) == 0 { 38 return fmt.Sprintf("no kind %q is registered for the default version", k.kind) 39 } 40 return fmt.Sprintf("no kind %q is registered for version %q", k.kind, k.version) 41 } 42 43 // IsNotRegisteredError returns true if the error indicates the provided 44 // object or input data is not registered. 45 func IsNotRegisteredError(err error) bool { 46 if err == nil { 47 return false 48 } 49 _, ok := err.(*notRegisteredErr) 50 return ok 51 } 52 53 type missingKindErr struct { 54 data string 55 } 56 57 func NewMissingKindErr(data string) error { 58 return &missingKindErr{data} 59 } 60 61 func (k *missingKindErr) Error() string { 62 return fmt.Sprintf("Object 'Kind' is missing in '%s'", k.data) 63 } 64 65 func IsMissingKind(err error) bool { 66 if err == nil { 67 return false 68 } 69 _, ok := err.(*missingKindErr) 70 return ok 71 } 72 73 type missingVersionErr struct { 74 data string 75 } 76 77 func NewMissingVersionErr(data string) error { 78 return &missingVersionErr{data} 79 } 80 81 func (k *missingVersionErr) Error() string { 82 return fmt.Sprintf("Object 'apiVersion' is missing in '%s'", k.data) 83 } 84 85 func IsMissingVersion(err error) bool { 86 if err == nil { 87 return false 88 } 89 _, ok := err.(*missingVersionErr) 90 return ok 91 }