Skip to content

Commit

Permalink
Do not obscure error message (#1227)
Browse files Browse the repository at this point in the history
Signed-off-by: Ralf Pannemans <[email protected]>
  • Loading branch information
c0d1ngm0nk3y authored Oct 27, 2023
1 parent 367b451 commit 2bf3ae7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 19 deletions.
16 changes: 8 additions & 8 deletions log/timelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ func (m mockLog) incr(key string) {
}
}

func (m mockLog) Debug(msg string) {
func (m mockLog) Debug(_ string) {
m.incr("Debug")
}
func (m mockLog) Debugf(fmt string, v ...interface{}) {
func (m mockLog) Debugf(_ string, _ ...interface{}) {
m.incr("Debug")
}
func (m mockLog) Info(msg string) {
func (m mockLog) Info(_ string) {
m.incr("Info")
}
func (m mockLog) Infof(fmt string, v ...interface{}) {
func (m mockLog) Infof(_ string, _ ...interface{}) {
m.incr("Info")
}
func (m mockLog) Warn(msg string) {
func (m mockLog) Warn(_ string) {
m.incr("Warn")
}
func (m mockLog) Warnf(fmt string, v ...interface{}) {
func (m mockLog) Warnf(_ string, _ ...interface{}) {
m.incr("Warn")
}
func (m mockLog) Error(msg string) {
func (m mockLog) Error(_ string) {
m.incr("Error")
}
func (m mockLog) Errorf(fmt string, v ...interface{}) {
func (m mockLog) Errorf(_ string, _ ...interface{}) {
m.incr("Error")
}

Expand Down
2 changes: 1 addition & 1 deletion platform/resolve_analyze_inputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func testResolveAnalyzeInputs(platformAPI string) func(t *testing.T, when spec.G
inputs.StackPath = "not-exist-stack.toml"
err := platform.ResolveInputs(platform.Analyze, inputs, logger)
h.AssertNotNil(t, err)
expected := "-run-image is required when there is no stack metadata available"
expected := "missing run image metadata (-run-image)"
h.AssertStringContains(t, err.Error(), expected)
})
})
Expand Down
2 changes: 1 addition & 1 deletion platform/resolve_create_inputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func testResolveCreateInputs(platformAPI string) func(t *testing.T, when spec.G,
inputs.StackPath = "not-exist-stack.toml"
err := platform.ResolveInputs(platform.Create, inputs, logger)
h.AssertNotNil(t, err)
expected := "-run-image is required when there is no stack metadata available"
expected := "missing run image metadata (-run-image)"
h.AssertStringContains(t, err.Error(), expected)
})
})
Expand Down
21 changes: 13 additions & 8 deletions platform/resolve_inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ import (
)

var (
ErrOutputImageRequired = "image argument is required"
ErrRunImageRequiredWhenNoStackMD = "-run-image is required when there is no stack metadata available"
ErrRunImageRequiredWhenNoRunMD = "-run-image is required when there is no run metadata available"
ErrSupplyOnlyOneRunImage = "supply only one of -run-image or (deprecated) -image"
ErrRunImageUnsupported = "-run-image is unsupported"
ErrImageUnsupported = "-image is unsupported"
MsgIgnoringLaunchCache = "Ignoring -launch-cache, only intended for use with -daemon"
// ErrOutputImageRequired user facing error message
ErrOutputImageRequired = "image argument is required"
// ErrRunImageRequiredWhenNoRunMD user facing error message
ErrRunImageRequiredWhenNoRunMD = "-run-image is required when there is no run metadata available"
// ErrSupplyOnlyOneRunImage user facing error message
ErrSupplyOnlyOneRunImage = "supply only one of -run-image or (deprecated) -image"
// ErrRunImageUnsupported user facing error message
ErrRunImageUnsupported = "-run-image is unsupported"
// ErrImageUnsupported user facing error message
ErrImageUnsupported = "-image is unsupported"
// MsgIgnoringLaunchCache user facing error message
MsgIgnoringLaunchCache = "Ignoring -launch-cache, only intended for use with -daemon"
)

func ResolveInputs(phase LifecyclePhase, i *LifecycleInputs, logger log.Logger) error {
Expand Down Expand Up @@ -178,7 +183,7 @@ func fillRunImageFromStackTOMLIfNeeded(i *LifecycleInputs, logger log.Logger) er
}
i.RunImageRef, err = BestRunImageMirrorFor(targetRegistry, stackMD.RunImage, i.AccessChecker())
if err != nil {
return errors.New(ErrRunImageRequiredWhenNoStackMD)
return err
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion platform/run_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
func BestRunImageMirrorFor(targetRegistry string, runImageMD files.RunImageForExport, checkReadAccess CheckReadAccess) (string, error) {
var runImageMirrors []string
if runImageMD.Image == "" {
return "", errors.New("missing run image metadata")
return "", errors.New("missing run image metadata (-run-image)")
}
runImageMirrors = append(runImageMirrors, runImageMD.Image)
runImageMirrors = append(runImageMirrors, runImageMD.Mirrors...)
Expand Down
13 changes: 13 additions & 0 deletions platform/run_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,18 @@ func testRunImage(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, name, "gcr.io/myorg/myrepo")
})
})

when("there is no read access", func() {
it("fails", func() {
noReadAccess := func(_ string, _ authn.Keychain) (bool, error) {
return false, nil
}

_, err := platform.BestRunImageMirrorFor("gcr.io", stackMD.RunImage, noReadAccess)
h.AssertNotNil(t, err)
expected := "failed to find accessible run image"
h.AssertStringContains(t, err.Error(), expected)
})
})
})
}

0 comments on commit 2bf3ae7

Please sign in to comment.