github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/test/custom/error.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 custom 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 func cmdRunRetrieveErr(command string, imageName string, err error) error { 27 return sErrors.NewError(err, 28 &proto.ActionableErr{ 29 Message: fmt.Sprintf("retrieving cmd %s: %s", command, err), 30 ErrCode: proto.StatusCode_TEST_CUSTOM_CMD_RETRIEVE_ERR, 31 Suggestions: []*proto.Suggestion{ 32 { 33 SuggestionCode: proto.SuggestionCode_CHECK_TEST_COMMAND_AND_IMAGE_NAME, 34 Action: fmt.Sprintf("Check the image name: %q and the command: %q", command, imageName), 35 }, 36 }, 37 }, 38 ) 39 } 40 41 func cmdRunParsingErr(command string, err error) error { 42 return sErrors.NewError(err, 43 &proto.ActionableErr{ 44 Message: fmt.Sprintf("unable to parse test command %s: %s", command, err), 45 ErrCode: proto.StatusCode_TEST_CUSTOM_CMD_PARSE_ERR, 46 Suggestions: []*proto.Suggestion{ 47 { 48 SuggestionCode: proto.SuggestionCode_CHECK_CUSTOM_COMMAND, 49 Action: fmt.Sprintf("Check the custom command contents: %q", command), 50 }, 51 }, 52 }, 53 ) 54 } 55 56 func cmdRunNonZeroExitErr(command string, err error) error { 57 return sErrors.NewError(err, 58 &proto.ActionableErr{ 59 Message: fmt.Sprintf("command %s finished with non-0 exit code: %s", command, err), 60 ErrCode: proto.StatusCode_TEST_CUSTOM_CMD_RUN_NON_ZERO_EXIT_ERR, 61 Suggestions: []*proto.Suggestion{ 62 { 63 SuggestionCode: proto.SuggestionCode_CHECK_CUSTOM_COMMAND, 64 Action: fmt.Sprintf("Check the custom command contents: %q", command), 65 }, 66 }, 67 }, 68 ) 69 } 70 71 func cmdRunTimedoutErr(timeoutSeconds int, err error) error { 72 return sErrors.NewError(err, 73 &proto.ActionableErr{ 74 Message: fmt.Sprintf("command timed out: %s", err), 75 ErrCode: proto.StatusCode_TEST_CUSTOM_CMD_RUN_TIMEDOUT_ERR, 76 Suggestions: []*proto.Suggestion{ 77 { 78 SuggestionCode: proto.SuggestionCode_FIX_CUSTOM_COMMAND_TIMEOUT, 79 Action: fmt.Sprintf("Fix the custom command timeoutSeconds: %d", timeoutSeconds), 80 }, 81 }, 82 }, 83 ) 84 } 85 86 func cmdRunCancelledErr(err error) error { 87 return sErrors.NewError(err, 88 &proto.ActionableErr{ 89 Message: fmt.Sprintf("command cancelled: %s", err), 90 ErrCode: proto.StatusCode_TEST_CUSTOM_CMD_RUN_CANCELLED_ERR, 91 }, 92 ) 93 } 94 95 func cmdRunExecutionErr(err error) error { 96 return sErrors.NewError(err, 97 &proto.ActionableErr{ 98 Message: fmt.Sprintf("command execution error: %s", err), 99 ErrCode: proto.StatusCode_TEST_CUSTOM_CMD_RUN_EXECUTION_ERR, 100 }, 101 ) 102 } 103 104 func cmdRunExited(err error) error { 105 return sErrors.NewError(err, 106 &proto.ActionableErr{ 107 Message: fmt.Sprintf("command exited: %s", err), 108 ErrCode: proto.StatusCode_TEST_CUSTOM_CMD_RUN_EXITED_ERR, 109 }, 110 ) 111 } 112 113 func cmdRunErr(err error) error { 114 return sErrors.NewError(err, 115 &proto.ActionableErr{ 116 Message: fmt.Sprintf("error running cmd: %s", err), 117 ErrCode: proto.StatusCode_TEST_CUSTOM_CMD_RUN_ERR, 118 }, 119 ) 120 } 121 122 func gettingDependenciesCommandErr(command string, err error) error { 123 return sErrors.NewError(err, 124 &proto.ActionableErr{ 125 Message: fmt.Sprintf("getting dependencies from command: %s: %s", command, err), 126 ErrCode: proto.StatusCode_TEST_CUSTOM_DEPENDENCIES_CMD_ERR, 127 Suggestions: []*proto.Suggestion{ 128 { 129 SuggestionCode: proto.SuggestionCode_CHECK_CUSTOM_COMMAND_DEPENDENCIES_CMD, 130 Action: fmt.Sprintf("Check the custom command dependencies command: %q", command), 131 }, 132 }, 133 }, 134 ) 135 } 136 137 func dependencyOutputUnmarshallErr(paths []string, err error) error { 138 return sErrors.NewError(err, 139 &proto.ActionableErr{ 140 Message: fmt.Sprintf("unmarshalling dependency output into string array: %s", err), 141 ErrCode: proto.StatusCode_TEST_CUSTOM_DEPENDENCIES_UNMARSHALL_ERR, 142 Suggestions: []*proto.Suggestion{ 143 { 144 SuggestionCode: proto.SuggestionCode_CHECK_CUSTOM_COMMAND_DEPENDENCIES_PATHS, 145 Action: fmt.Sprintf("Check the custom command dependencies paths: %q", paths), 146 }, 147 }, 148 }, 149 ) 150 }