Improve error message for s2i unsupported runtimes (#1080)

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2022-06-27 22:41:28 +02:00 committed by GitHub
parent f066218042
commit d5748f0e4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -32,10 +32,6 @@ import (
var (
// ErrRuntimeRequired indicates the required value of Function Runtime was not provided
ErrRuntimeRequired = errors.New("runtime is required to build")
// ErrRuntimeNotSupported indicates the given runtime is not (yet) supported
// by this builder.
ErrRuntimeNotSupported = errors.New("runtime not supported")
)
// DefaultBuilderImages for s2i builders indexed by Runtime Language
@ -386,5 +382,18 @@ func builderImage(f fn.Function) (string, error) {
return v, nil
}
return "", ErrRuntimeNotSupported
return "", ErrRuntimeNotSupported{f.Runtime}
}
func IsErrRuntimeNotSupported(err error) bool {
var e ErrRuntimeNotSupported
return errors.As(err, &e)
}
type ErrRuntimeNotSupported struct {
Runtime string
}
func (e ErrRuntimeNotSupported) Error() string {
return fmt.Sprintf("the s2i builder has no default builder image for the %q language runtime (try specifying builder image or use different build strategy)", e.Runtime)
}

View File

@ -47,7 +47,7 @@ func Test_ErrRuntimeNotSupported(t *testing.T) {
b := s2i.NewBuilder()
err := b.Build(context.Background(), fn.Function{Runtime: "unsupported"})
if !errors.Is(err, s2i.ErrRuntimeNotSupported) {
if !s2i.IsErrRuntimeNotSupported(err) {
t.Fatal("expected ErrRuntimeNotSupported not received")
}
}