sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/machinery/errors.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 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 machinery 18 19 import ( 20 "fmt" 21 ) 22 23 // This file contains the errors returned by the scaffolding machinery 24 // They are exported to be able to check which kind of error was returned 25 26 // ValidateError is a wrapper error that will be used for errors returned by RequiresValidation.Validate 27 type ValidateError struct { 28 error 29 } 30 31 // Unwrap implements Wrapper interface 32 func (e ValidateError) Unwrap() error { 33 return e.error 34 } 35 36 // SetTemplateDefaultsError is a wrapper error that will be used for errors returned by Template.SetTemplateDefaults 37 type SetTemplateDefaultsError struct { 38 error 39 } 40 41 // Unwrap implements Wrapper interface 42 func (e SetTemplateDefaultsError) Unwrap() error { 43 return e.error 44 } 45 46 // ExistsFileError is a wrapper error that will be used for errors when checking for a file existence 47 type ExistsFileError struct { 48 error 49 } 50 51 // Unwrap implements Wrapper interface 52 func (e ExistsFileError) Unwrap() error { 53 return e.error 54 } 55 56 // OpenFileError is a wrapper error that will be used for errors when opening a file 57 type OpenFileError struct { 58 error 59 } 60 61 // Unwrap implements Wrapper interface 62 func (e OpenFileError) Unwrap() error { 63 return e.error 64 } 65 66 // CreateDirectoryError is a wrapper error that will be used for errors when creating a directory 67 type CreateDirectoryError struct { 68 error 69 } 70 71 // Unwrap implements Wrapper interface 72 func (e CreateDirectoryError) Unwrap() error { 73 return e.error 74 } 75 76 // CreateFileError is a wrapper error that will be used for errors when creating a file 77 type CreateFileError struct { 78 error 79 } 80 81 // Unwrap implements Wrapper interface 82 func (e CreateFileError) Unwrap() error { 83 return e.error 84 } 85 86 // ReadFileError is a wrapper error that will be used for errors when reading a file 87 type ReadFileError struct { 88 error 89 } 90 91 // Unwrap implements Wrapper interface 92 func (e ReadFileError) Unwrap() error { 93 return e.error 94 } 95 96 // WriteFileError is a wrapper error that will be used for errors when writing a file 97 type WriteFileError struct { 98 error 99 } 100 101 // Unwrap implements Wrapper interface 102 func (e WriteFileError) Unwrap() error { 103 return e.error 104 } 105 106 // CloseFileError is a wrapper error that will be used for errors when closing a file 107 type CloseFileError struct { 108 error 109 } 110 111 // Unwrap implements Wrapper interface 112 func (e CloseFileError) Unwrap() error { 113 return e.error 114 } 115 116 // ModelAlreadyExistsError is returned if the file is expected not to exist but a previous model does 117 type ModelAlreadyExistsError struct { 118 path string 119 } 120 121 // Error implements error interface 122 func (e ModelAlreadyExistsError) Error() string { 123 return fmt.Sprintf("failed to create %s: model already exists", e.path) 124 } 125 126 // UnknownIfExistsActionError is returned if the if-exists-action is unknown 127 type UnknownIfExistsActionError struct { 128 path string 129 ifExistsAction IfExistsAction 130 } 131 132 // Error implements error interface 133 func (e UnknownIfExistsActionError) Error() string { 134 return fmt.Sprintf("unknown behavior if file exists (%d) for %s", e.ifExistsAction, e.path) 135 } 136 137 // FileAlreadyExistsError is returned if the file is expected not to exist but it does 138 type FileAlreadyExistsError struct { 139 path string 140 } 141 142 // Error implements error interface 143 func (e FileAlreadyExistsError) Error() string { 144 return fmt.Sprintf("failed to create %s: file already exists", e.path) 145 }