From 716106b73c1bfae455f6130e817ca3b2477e9797 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Fri, 22 Dec 2023 15:16:46 -0500 Subject: [PATCH] handle missing region --- cmd/sst/main.go | 7 ++++++- examples/test/sst.config.ts | 1 - internal/util/util.go | 12 ++++++++++++ pkg/project/provider/provider.go | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cmd/sst/main.go b/cmd/sst/main.go index 73097a447..1124b54a4 100644 --- a/cmd/sst/main.go +++ b/cmd/sst/main.go @@ -17,6 +17,7 @@ import ( "github.com/manifoldco/promptui" "github.com/sst/ion/cmd/sst/ui" + "github.com/sst/ion/internal/util" "github.com/sst/ion/pkg/global" "github.com/sst/ion/pkg/project" @@ -260,7 +261,11 @@ func main() { err := app.Run(os.Args) if err != nil { - panic(err) + if err, ok := err.(*util.ReadableError); ok { + fmt.Println(err.Message) + } else { + panic(err) + } } } diff --git a/examples/test/sst.config.ts b/examples/test/sst.config.ts index bc33fb18c..f89ce4b77 100644 --- a/examples/test/sst.config.ts +++ b/examples/test/sst.config.ts @@ -4,7 +4,6 @@ export default $config({ app(input) { return { name: "test", - region: "us-east-1", removalPolicy: "remove", providers: { aws: { diff --git a/internal/util/util.go b/internal/util/util.go index 9344034ce..09aded0a3 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -13,3 +13,15 @@ func RandomString(length int) string { } return string(b) } + +type ReadableError struct { + Message string +} + +func NewReadableError(message string) *ReadableError { + return &ReadableError{Message: message} +} + +func (e *ReadableError) Error() string { + return e.Message +} diff --git a/pkg/project/provider/provider.go b/pkg/project/provider/provider.go index 8c693f601..51015ebb2 100644 --- a/pkg/project/provider/provider.go +++ b/pkg/project/provider/provider.go @@ -191,6 +191,9 @@ func (a *AwsProvider) Init(workdir string, args map[string]string) (err error) { if err != nil { return err } + if cfg.Region == "" { + return util.NewReadableError("No region found in AWS config") + } a.config = cfg bucket, err := a.resolveBucket()