|
| 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 | +// ModelAlreadyExistsError is returned if the file is expected not to exist but a previous model does |
| 47 | +type ModelAlreadyExistsError struct { |
| 48 | + path string |
| 49 | +} |
| 50 | + |
| 51 | +// Error implements error interface |
| 52 | +func (e ModelAlreadyExistsError) Error() string { |
| 53 | + return fmt.Sprintf("failed to create %s: model already exists", e.path) |
| 54 | +} |
| 55 | + |
| 56 | +// UnknownIfExistsActionError is returned if the if-exists-action is unknown |
| 57 | +type UnknownIfExistsActionError struct { |
| 58 | + path string |
| 59 | + ifExistsAction IfExistsAction |
| 60 | +} |
| 61 | + |
| 62 | +// Error implements error interface |
| 63 | +func (e UnknownIfExistsActionError) Error() string { |
| 64 | + return fmt.Sprintf("unknown behavior if file exists (%d) for %s", e.ifExistsAction, e.path) |
| 65 | +} |
| 66 | + |
| 67 | +// FileAlreadyExistsError is returned if the file is expected not to exist but it does |
| 68 | +type FileAlreadyExistsError struct { |
| 69 | + path string |
| 70 | +} |
| 71 | + |
| 72 | +// Error implements error interface |
| 73 | +func (e FileAlreadyExistsError) Error() string { |
| 74 | + return fmt.Sprintf("failed to create %s: file already exists", e.path) |
| 75 | +} |
0 commit comments