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