Skip to content

Commit

Permalink
Do not obscure error message
Browse files Browse the repository at this point in the history
Signed-off-by: Ralf Pannemans <ralf.pannemans@sap.com>
  • Loading branch information
c0d1ngm0nk3y committed Oct 27, 2023
1 parent 367b451 commit d8d73ae
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
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
15 changes: 7 additions & 8 deletions platform/resolve_inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check failure on line 14 in platform/resolve_inputs.go

View workflow job for this annotation

GitHub Actions / test-linux-amd64

exported: exported var ErrOutputImageRequired should have comment or be unexported (revive)

Check failure on line 14 in platform/resolve_inputs.go

View workflow job for this annotation

GitHub Actions / test-linux-arm64

exported: exported var ErrOutputImageRequired should have comment or be unexported (revive)

Check failure on line 14 in platform/resolve_inputs.go

View workflow job for this annotation

GitHub Actions / test-windows

exported: exported var ErrOutputImageRequired should have comment or be unexported (revive)
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 {
Expand Down Expand Up @@ -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
}
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 d8d73ae

Please sign in to comment.