github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/errors/errors.go (about) 1 /* 2 Copyright 2021 The Skaffold 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 errors 18 19 import ( 20 "fmt" 21 22 sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" 23 "github.com/GoogleContainerTools/skaffold/proto/v1" 24 ) 25 26 // ConfigParsingError returns a generic config parsing error 27 func ConfigParsingError(err error) error { 28 return sErrors.NewError(err, 29 &proto.ActionableErr{ 30 Message: fmt.Sprintf("error parsing skaffold configuration file: %v", err), 31 ErrCode: proto.StatusCode_CONFIG_FILE_PARSING_ERR, 32 }) 33 } 34 35 // MainConfigFileNotFoundErr specifies main configuration file not found 36 func MainConfigFileNotFoundErr(file string, err error) error { 37 return sErrors.NewError(err, 38 &proto.ActionableErr{ 39 Message: fmt.Sprintf("unable to find configuration file %q: %v", file, err), 40 ErrCode: proto.StatusCode_CONFIG_FILE_NOT_FOUND_ERR, 41 Suggestions: []*proto.Suggestion{ 42 { 43 SuggestionCode: proto.SuggestionCode_CONFIG_CHECK_FILE_PATH, 44 Action: fmt.Sprintf("Check that the specified configuration file exists at %q", file), 45 }, 46 }, 47 }) 48 } 49 50 // DependencyConfigFileNotFoundErr specifies dependency configuration file not found 51 func DependencyConfigFileNotFoundErr(depFile, parentFile string, err error) error { 52 return sErrors.NewError(err, 53 &proto.ActionableErr{ 54 Message: fmt.Sprintf("could not find skaffold config file %q that is referenced as a dependency in config file %q: %v", depFile, parentFile, err), 55 ErrCode: proto.StatusCode_CONFIG_DEPENDENCY_NOT_FOUND_ERR, 56 Suggestions: []*proto.Suggestion{ 57 { 58 SuggestionCode: proto.SuggestionCode_CONFIG_CHECK_DEPENDENCY_DEFINITION, 59 Action: fmt.Sprintf("Modify the `requires` definition in the configuration file %q to point to the correct path for the dependency %q", parentFile, depFile), 60 }, 61 }, 62 }) 63 } 64 65 // BadConfigFilterErr specifies no configs matched the configs filter 66 func BadConfigFilterErr(filter []string) error { 67 msg := fmt.Sprintf("did not find any configs matching selection %v", filter) 68 return sErrors.NewError(fmt.Errorf(msg), 69 &proto.ActionableErr{ 70 Message: msg, 71 ErrCode: proto.StatusCode_CONFIG_BAD_FILTER_ERR, 72 Suggestions: []*proto.Suggestion{ 73 { 74 SuggestionCode: proto.SuggestionCode_CONFIG_CHECK_FILTER, 75 Action: "Check that the arguments to the `-m` or `--module` flag are valid config names", 76 }, 77 }, 78 }) 79 } 80 81 // ZeroConfigsParsedErr specifies that the config file is empty 82 func ZeroConfigsParsedErr(file string) error { 83 msg := fmt.Sprintf("failed to get any valid configs from file %q", file) 84 return sErrors.NewError(fmt.Errorf(msg), 85 &proto.ActionableErr{ 86 Message: msg, 87 ErrCode: proto.StatusCode_CONFIG_ZERO_FOUND_ERR, 88 }) 89 } 90 91 // DuplicateConfigNamesInSameFileErr specifies that multiple configs have the same name in current config file 92 func DuplicateConfigNamesInSameFileErr(config, file string) error { 93 msg := fmt.Sprintf("multiple skaffold configs named %q found in file %q", config, file) 94 return sErrors.NewError(fmt.Errorf(msg), 95 &proto.ActionableErr{ 96 Message: msg, 97 ErrCode: proto.StatusCode_CONFIG_DUPLICATE_NAMES_SAME_FILE_ERR, 98 Suggestions: []*proto.Suggestion{ 99 { 100 SuggestionCode: proto.SuggestionCode_CONFIG_CHANGE_NAMES, 101 Action: fmt.Sprintf("Change the name of one of the occurrences of config %q in file %q to make it unique", config, file), 102 }, 103 }, 104 }) 105 } 106 107 // DuplicateConfigNamesAcrossFilesErr specifies that multiple configs have the same name in different files 108 func DuplicateConfigNamesAcrossFilesErr(config, file1, file2 string) error { 109 msg := fmt.Sprintf("skaffold config named %q found in multiple files: %q and %q", config, file1, file2) 110 return sErrors.NewError(fmt.Errorf(msg), 111 &proto.ActionableErr{ 112 Message: msg, 113 ErrCode: proto.StatusCode_CONFIG_DUPLICATE_NAMES_ACROSS_FILES_ERR, 114 Suggestions: []*proto.Suggestion{ 115 { 116 SuggestionCode: proto.SuggestionCode_CONFIG_CHANGE_NAMES, 117 Action: fmt.Sprintf("Change the name of config %q in file %q or file %q to make it unique", config, file1, file2), 118 }, 119 }, 120 }) 121 } 122 123 // ConfigProfileActivationErr specifies that profile activation failed for this config 124 func ConfigProfileActivationErr(config, file string, err error) error { 125 return sErrors.NewError(err, 126 &proto.ActionableErr{ 127 Message: fmt.Sprintf("failed to apply profiles to config %q defined in file %q: %v", config, file, err), 128 ErrCode: proto.StatusCode_CONFIG_APPLY_PROFILES_ERR, 129 Suggestions: []*proto.Suggestion{ 130 { 131 SuggestionCode: proto.SuggestionCode_CONFIG_CHECK_PROFILE_DEFINITION, 132 Action: fmt.Sprintf("There's an issue with one of the profiles defined in config %q in file %q; refer to the documentation on how to author valid profiles: https://skaffold.dev/docs/environment/profiles/", config, file), 133 }, 134 }, 135 }) 136 } 137 138 // ConfigSetDefaultValuesErr specifies that default values failed to be applied for this config 139 func ConfigSetDefaultValuesErr(config, file string, err error) error { 140 return sErrors.NewError(err, 141 &proto.ActionableErr{ 142 Message: fmt.Sprintf("failed to set default values for config %q defined in file %q: %v", config, file, err), 143 ErrCode: proto.StatusCode_CONFIG_DEFAULT_VALUES_ERR, 144 }) 145 } 146 147 // ConfigSetAbsFilePathsErr specifies that substituting absolute filepaths failed for this config 148 func ConfigSetAbsFilePathsErr(config, file string, err error) error { 149 return sErrors.NewError(err, 150 &proto.ActionableErr{ 151 Message: fmt.Sprintf("failed to set absolute filepaths for config %q defined in file %q: %v", config, file, err), 152 ErrCode: proto.StatusCode_CONFIG_FILE_PATHS_SUBSTITUTION_ERR, 153 }) 154 } 155 156 // ConfigProfilesNotMatchedErr specifies that the profiles selected via the `--profile` flag could not be matched against any config 157 func ConfigProfilesNotMatchedErr(profiles []string) error { 158 msg := fmt.Sprintf("profile selection %q did not match those defined in any configurations", profiles) 159 return sErrors.NewError(fmt.Errorf(msg), 160 &proto.ActionableErr{ 161 Message: msg, 162 ErrCode: proto.StatusCode_CONFIG_PROFILES_NOT_FOUND_ERR, 163 Suggestions: []*proto.Suggestion{ 164 { 165 SuggestionCode: proto.SuggestionCode_CONFIG_CHECK_PROFILE_SELECTION, 166 Action: `Check that values specified in the "--profile" or "-p" flags are valid profile names`, 167 }, 168 }, 169 }) 170 } 171 172 // ConfigProfileConflictErr specifies that the same config is imported with different set of profiles. 173 func ConfigProfileConflictErr(config, file string) error { 174 msg := fmt.Sprintf("config %q defined in file %q imported multiple times with different set of profiles", config, file) 175 return sErrors.NewError(fmt.Errorf(msg), 176 &proto.ActionableErr{ 177 Message: msg, 178 ErrCode: proto.StatusCode_CONFIG_MULTI_IMPORT_PROFILE_CONFLICT_ERR, 179 Suggestions: []*proto.Suggestion{ 180 { 181 SuggestionCode: proto.SuggestionCode_CONFIG_CHECK_DEPENDENCY_PROFILES_SELECTION, 182 Action: "Check that all occurrences of the specified config dependency use the same set of profiles; refer to the documentation on how to author config dependencies: https://skaffold.dev/docs/design/config/#configuration-dependencies", 183 }, 184 }, 185 }) 186 } 187 188 // ConfigUnknownAPIVersionErr specifies that the config API version doesn't match any known versions. 189 func ConfigUnknownAPIVersionErr(version string) error { 190 msg := fmt.Sprintf("unknown skaffold config API version %q", version) 191 return sErrors.NewError(fmt.Errorf(msg), 192 &proto.ActionableErr{ 193 Message: msg, 194 ErrCode: proto.StatusCode_CONFIG_UNKNOWN_API_VERSION_ERR, 195 Suggestions: []*proto.Suggestion{ 196 { 197 SuggestionCode: proto.SuggestionCode_CONFIG_FIX_API_VERSION, 198 Action: "Set the config 'apiVersion' to a known value. Check https://skaffold.dev/docs/references/yaml/ for the list of valid API versions. Otherwise, check that your skaffold version is up-to-date", 199 }, 200 }, 201 }) 202 }