github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/inspect/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 inspect 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 // BuildEnvAlreadyExists specifies that there's an existing build environment definition for the same type. 27 func BuildEnvAlreadyExists(b BuildEnv, filename string, profile string) error { 28 var msg string 29 if profile == "" { 30 msg = fmt.Sprintf("trying to create a %q build environment definition that already exists, in file %s", b, filename) 31 } else { 32 msg = fmt.Sprintf("trying to create a %q build environment definition that already exists, in profile %q in file %s", b, profile, filename) 33 } 34 return sErrors.NewError(fmt.Errorf(msg), 35 &proto.ActionableErr{ 36 Message: msg, 37 ErrCode: proto.StatusCode_INSPECT_BUILD_ENV_ALREADY_EXISTS_ERR, 38 Suggestions: []*proto.Suggestion{ 39 { 40 SuggestionCode: proto.SuggestionCode_INSPECT_USE_MODIFY_OR_NEW_PROFILE, 41 Action: "Use the `modify` command instead of the `add` command to overwrite fields for an already existing build environment type. Otherwise pass the `--profile` flag with a unique name to create the new build environment definition in a new profile instead", 42 }, 43 }, 44 }) 45 } 46 47 // BuildEnvNotFound specifies that the target build environment definition doesn't exist. 48 func BuildEnvNotFound(b BuildEnv, filename string, profile string) error { 49 var msg string 50 if profile == "" { 51 msg = fmt.Sprintf("trying to modify a %q build environment definition that doesn't exist, in file %s", b, filename) 52 } else { 53 msg = fmt.Sprintf("trying to modify a %q build environment definition that doesn't exist, in profile %q in file %s", b, profile, filename) 54 } 55 return sErrors.NewError(fmt.Errorf(msg), 56 &proto.ActionableErr{ 57 Message: msg, 58 ErrCode: proto.StatusCode_INSPECT_BUILD_ENV_INCORRECT_TYPE_ERR, 59 Suggestions: []*proto.Suggestion{ 60 { 61 SuggestionCode: proto.SuggestionCode_INSPECT_USE_ADD_BUILD_ENV, 62 Action: "Check that the target build environment definition already exists. Otherwise use the `add` command instead of the `modify` command to create it", 63 }, 64 }, 65 }) 66 } 67 68 // ProfileNotFound specifies that the target profile doesn't exist 69 func ProfileNotFound(profile string) error { 70 msg := fmt.Sprintf("trying to modify a profile %q that doesn't exist", profile) 71 return sErrors.NewError(fmt.Errorf(msg), 72 &proto.ActionableErr{ 73 Message: msg, 74 ErrCode: proto.StatusCode_INSPECT_PROFILE_NOT_FOUND_ERR, 75 Suggestions: []*proto.Suggestion{ 76 { 77 SuggestionCode: proto.SuggestionCode_INSPECT_CHECK_INPUT_PROFILE, 78 Action: "Check that the `--profile` flag matches at least one existing profile. Otherwise use the `add` command instead of the `modify` command to create it", 79 }, 80 }, 81 }) 82 }