Skip to content

Commit 547525c

Browse files
committed
feat: add NotSupportedError type
1 parent 2f7926d commit 547525c

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

pkg/functiondockerfile/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func Generate(f *stack.Function, version, provider string, fwriter io.Writer) er
6161
}
6262
generator, ok := generators[rt]
6363
if generator == nil || !ok {
64-
return errors.New("could not build dockerfile from " + f.Handler + ", extension not supported")
64+
return utils.NewNotSupportedErr("could not build dockerfile from " + f.Handler + ", extension not supported")
6565
}
6666
return generator(f, version, provider, fwriter)
6767
}

pkg/provider/generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ func NewProvider(s *stack.Stack, t *target.Target) (types.Provider, error) {
2828
case "local":
2929
return local.New(s, t)
3030
default:
31-
return nil, nil
31+
return nil, utils.NewNotSupportedErr(fmt.Sprintf("provider %s is not supported", t.Provider))
3232
}
3333
}

pkg/provider/local/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (l *local) storage(deploymentName string) error {
4444
consolePort := uint16(ports[1])
4545

4646
minioImage := "minio/minio:latest"
47-
err = l.cr.Pull(minioImage)
47+
err = l.cr.ImagePull(minioImage)
4848
if err != nil {
4949
return err
5050
}

pkg/utils/errors.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package utils
1818

1919
import (
20+
"errors"
2021
"strings"
2122
"sync"
2223
)
@@ -58,3 +59,21 @@ func (e *ErrorList) Aggregate() error {
5859
}
5960
return e
6061
}
62+
63+
// NotSupportedError indicates that a request operation cannot be performed,
64+
// because it is unsupported.
65+
// Functions and methods should not return this error but should instead
66+
// return an error including appropriate context that satisfies
67+
// errors.Is(err, errors.NotSupportedError)
68+
// either by directly wrapping NotSupportedError or by implementing an Is method.
69+
type NotSupportedError struct {
70+
error
71+
}
72+
73+
func NewNotSupportedErr(message string) error {
74+
return &NotSupportedError{error: errors.New(message)}
75+
}
76+
77+
func (*NotSupportedError) Is(err error) bool {
78+
return strings.Contains(err.Error(), "unsupported") || strings.Contains(err.Error(), "not supported")
79+
}

0 commit comments

Comments
 (0)