Skip to content

Commit 8a1586b

Browse files
authored
Show more detailed error when unknown Project (#5939)
* Show more deatiled error when unknown Project * fix tests
1 parent e15b5c9 commit 8a1586b

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

pkg/skaffold/build/build_problems.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"fmt"
2121
"regexp"
2222

23+
"github.com/sirupsen/logrus"
24+
2325
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
2426
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
2527
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
@@ -38,14 +40,16 @@ const (
3840
)
3941

4042
var (
41-
nilSuggestions = func(cfg interface{}) []*proto.Suggestion { return nil }
43+
unknownProjectErr = fmt.Sprintf(".*(%s.* unknown: Project.*)", PushImageErr)
44+
nilSuggestions = func(cfg interface{}) []*proto.Suggestion { return nil }
4245
// for testing
4346
getConfigForCurrentContext = config.GetConfigForCurrentKubectx
4447
problems = []sErrors.Problem{
4548
{
4649
Regexp: re(fmt.Sprintf(".*%s.* denied: .*", PushImageErr)),
4750
ErrCode: proto.StatusCode_BUILD_PUSH_ACCESS_DENIED,
48-
Description: func(error) string {
51+
Description: func(err error) string {
52+
logrus.Tracef("error building %s", err)
4953
return "Build Failed. No push access to specified image repository"
5054
},
5155
Suggestion: suggestBuildPushAccessDeniedAction,
@@ -59,9 +63,14 @@ var (
5963
Suggestion: nilSuggestions,
6064
},
6165
{
62-
Regexp: re(fmt.Sprintf(".*%s.* unknown: Project", PushImageErr)),
63-
Description: func(error) string {
64-
return "Build Failed"
66+
Regexp: re(unknownProjectErr),
67+
Description: func(err error) string {
68+
logrus.Tracef("error building %s", err)
69+
matchExp := re(unknownProjectErr)
70+
if match := matchExp.FindStringSubmatch(err.Error()); len(match) >= 2 {
71+
return fmt.Sprintf("Build Failed. %s", match[1])
72+
}
73+
return fmt.Sprintf("Build Failed due to %s", err)
6574
},
6675
ErrCode: proto.StatusCode_BUILD_PROJECT_NOT_FOUND,
6776
Suggestion: func(interface{}) []*proto.Suggestion {
@@ -75,6 +84,7 @@ var (
7584
Regexp: re(dockerConnectionFailed),
7685
ErrCode: proto.StatusCode_BUILD_DOCKER_DAEMON_NOT_RUNNING,
7786
Description: func(err error) string {
87+
logrus.Tracef("error building %s", err)
7888
matchExp := re(dockerConnectionFailed)
7989
if match := matchExp.FindStringSubmatch(err.Error()); len(match) >= 2 {
8090
return fmt.Sprintf("Build Failed. %s", match[1])

pkg/skaffold/build/build_problems_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ func TestBuildProblems(t *testing.T) {
106106
},
107107
{
108108
description: "unknown project error",
109-
err: fmt.Errorf("build failed: could not push image: unknown: Project"),
110-
expected: "Build Failed. Check your GCR project.",
109+
err: fmt.Errorf("build failed: could not push image: unknown: Project test"),
110+
expected: "Build Failed. could not push image: unknown: Project test. Check your GCR project.",
111111
expectedAE: &proto.ActionableErr{
112112
ErrCode: proto.StatusCode_BUILD_PROJECT_NOT_FOUND,
113-
Message: "build failed: could not push image: unknown: Project",
113+
Message: "build failed: could not push image: unknown: Project test",
114114
Suggestions: []*proto.Suggestion{{
115115
SuggestionCode: proto.SuggestionCode_CHECK_GCLOUD_PROJECT,
116116
Action: "Check your GCR project",

0 commit comments

Comments
 (0)