From d8d73ae4ffc9b8d4ff700fd9fb0946a9520ff386 Mon Sep 17 00:00:00 2001 From: Ralf Pannemans Date: Fri, 27 Oct 2023 10:25:48 +0200 Subject: [PATCH] Do not obscure error message Signed-off-by: Ralf Pannemans --- platform/resolve_analyze_inputs_test.go | 2 +- platform/resolve_create_inputs_test.go | 2 +- platform/resolve_inputs.go | 15 +++++++-------- platform/run_image.go | 2 +- platform/run_image_test.go | 13 +++++++++++++ 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/platform/resolve_analyze_inputs_test.go b/platform/resolve_analyze_inputs_test.go index 4f4b560fb..5e738cf42 100644 --- a/platform/resolve_analyze_inputs_test.go +++ b/platform/resolve_analyze_inputs_test.go @@ -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) }) }) diff --git a/platform/resolve_create_inputs_test.go b/platform/resolve_create_inputs_test.go index 51d8fbc0e..105afcad6 100644 --- a/platform/resolve_create_inputs_test.go +++ b/platform/resolve_create_inputs_test.go @@ -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) }) }) diff --git a/platform/resolve_inputs.go b/platform/resolve_inputs.go index 743784ee5..212ac7e61 100644 --- a/platform/resolve_inputs.go +++ b/platform/resolve_inputs.go @@ -11,13 +11,12 @@ 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 = "image argument is required" + 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" ) func ResolveInputs(phase LifecyclePhase, i *LifecycleInputs, logger log.Logger) error { @@ -178,7 +177,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 } diff --git a/platform/run_image.go b/platform/run_image.go index c0273e188..12cc283b7 100644 --- a/platform/run_image.go +++ b/platform/run_image.go @@ -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...) diff --git a/platform/run_image_test.go b/platform/run_image_test.go index 0025ddfb7..bc7a6b830 100644 --- a/platform/run_image_test.go +++ b/platform/run_image_test.go @@ -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) + }) + }) }) }