Skip to content

Commit

Permalink
dev: if state bucket is missing print a more helpful error
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Aug 22, 2024
1 parent 5b97858 commit 7a42343
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 127 deletions.
3 changes: 2 additions & 1 deletion cmd/sst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/fatih/color"
"github.com/sst/ion/cmd/sst/cli"
"github.com/sst/ion/cmd/sst/mosaic/dev"
"github.com/sst/ion/cmd/sst/mosaic/errors"
"github.com/sst/ion/cmd/sst/mosaic/ui"
"github.com/sst/ion/internal/util"
"github.com/sst/ion/pkg/global"
Expand Down Expand Up @@ -55,7 +56,7 @@ func main() {
})
err := run()
if err != nil {
err := TransformError(err)
err := errors.Transform(err)
errorMessage := err.Error()
if len(errorMessage) > 255 {
errorMessage = errorMessage[:255]
Expand Down
13 changes: 12 additions & 1 deletion cmd/sst/mosaic/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import (
"log/slog"
"reflect"

"github.com/sst/ion/cmd/sst/mosaic/errors"
"github.com/sst/ion/cmd/sst/mosaic/watcher"
"github.com/sst/ion/internal/util"
"github.com/sst/ion/pkg/bus"
"github.com/sst/ion/pkg/project"
"github.com/sst/ion/pkg/server"
)

type DeployRequestedEvent struct{}
type DeployFailedEvent struct {
Error string
}

func Start(ctx context.Context, p *project.Project, server *server.Server) error {
defer slog.Info("deployer done")
Expand All @@ -31,11 +36,17 @@ func Start(ctx context.Context, p *project.Project, server *server.Server) error
case *watcher.FileChangedEvent, *DeployRequestedEvent:
if evt, ok := evt.(*watcher.FileChangedEvent); !ok || watchedFiles[evt.Path] {
slog.Info("deployer deploying")
p.Run(ctx, &project.StackInput{
err := p.Run(ctx, &project.StackInput{
Command: "deploy",
Dev: true,
ServerPort: server.Port,
})
if err != nil {
transformed := errors.Transform(err)
if _, ok := transformed.(*util.ReadableError); ok {
bus.Publish(&DeployFailedEvent{Error: transformed.Error()})
}
}
}
}
continue
Expand Down
5 changes: 3 additions & 2 deletions cmd/sst/errors.go → cmd/sst/mosaic/errors/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package errors

import (
"errors"
Expand All @@ -10,7 +10,7 @@ import (
"github.com/sst/ion/pkg/server"
)

func TransformError(err error) error {
func Transform(err error) error {
mapping := map[error]string{
project.ErrInvalidStageName: "The stage name is invalid. It can only contain alphanumeric characters and hyphens.",
project.ErrInvalidAppName: "The app name is invalid. It can only contain alphanumeric characters and hyphens.",
Expand All @@ -23,6 +23,7 @@ func TransformError(err error) error {
project.ErrVersionInvalid: "The version range defined in the config is invalid",
provider.ErrCloudflareMissingAccount: "The Cloudflare Account ID was not able to be determined from this token. Make sure it has permissions to fetch account information or you can set the CLOUDFLARE_DEFAULT_ACCOUNT_ID environment variable to the account id you want to use.",
server.ErrServerNotFound: "You are currently trying to run a frontend or some other process on its own - starting from sst v0.1.32 `sst dev` can bring up all of the processes in your application in a single window. Simply run `sst dev` in the same directory as your `sst.config.ts`. If this is not clear check out the monorepo example here: https://github.com/sst/ion/tree/dev/examples/aws-monorepo\n\n If you prefer running your processes in different terminal windows, you can start just the deploy process by running `sst dev --mode=basic` and then bring up your process with `sst dev -- <command>` in another terminal window.",
provider.ErrBucketMissing: "The state bucket is missing, it may have been accidentally deleted. Go to https://console.aws.amazon.com/systems-manager/parameters/%252Fsst%252Fbootstrap/description?region=us-east-1&tab=Table and check if the state bucket mentioned there exists. If it doesn't you can recreate it or delete the `/sst/bootstrap` key to force recreation.",
}

readable := []error{
Expand Down
4 changes: 4 additions & 0 deletions cmd/sst/mosaic/ui/footer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/charmbracelet/x/ansi"
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/sst/ion/cmd/sst/mosaic/deployer"
"github.com/sst/ion/pkg/project"
"golang.org/x/crypto/ssh/terminal"
)
Expand Down Expand Up @@ -175,6 +176,9 @@ func (m *footer) Update(msg any) {
case *project.ConcurrentUpdateEvent:
m.Reset()
break
case *deployer.DeployFailedEvent:
m.Reset()
break
case *apitype.ResourcePreEvent:
if slices.Contains(IGNORED_RESOURCES, msg.Metadata.Type) {
break
Expand Down
5 changes: 5 additions & 0 deletions cmd/sst/mosaic/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/sst/ion/cmd/sst/mosaic/aws"
"github.com/sst/ion/cmd/sst/mosaic/cloudflare"
"github.com/sst/ion/cmd/sst/mosaic/deployer"
"github.com/sst/ion/cmd/sst/mosaic/ui/common"
"github.com/sst/ion/pkg/project"

Expand Down Expand Up @@ -174,6 +175,10 @@ func (u *UI) Event(unknown interface{}) {
u.reset()
u.printEvent(TEXT_DANGER, "Locked", "A concurrent update was detected on the app. Run `sst unlock` to remove the lock and try again.")

case *deployer.DeployFailedEvent:
u.reset()
u.printEvent(TEXT_DANGER, "Error", evt.Error)

case *project.StackCommandEvent:
u.reset()
u.header(evt.Version, evt.App, evt.Stage)
Expand Down
4 changes: 4 additions & 0 deletions cmd/sst/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/sst/ion/cmd/sst/cli"
"github.com/sst/ion/cmd/sst/mosaic/aws"
"github.com/sst/ion/cmd/sst/mosaic/cloudflare"
"github.com/sst/ion/cmd/sst/mosaic/deployer"
"github.com/sst/ion/cmd/sst/mosaic/dev"
"github.com/sst/ion/cmd/sst/mosaic/ui"
"github.com/sst/ion/cmd/sst/mosaic/ui/common"
"github.com/sst/ion/pkg/project"
"github.com/sst/ion/pkg/server"
)
Expand Down Expand Up @@ -41,6 +43,8 @@ func CmdUI(c *cli.Cli) error {
}
if filter == "sst" || filter == "" {
types = append(types,
common.StdoutEvent{},
deployer.DeployFailedEvent{},
project.StackCommandEvent{},
project.ConcurrentUpdateEvent{},
project.StackCommandEvent{},
Expand Down
Loading

0 comments on commit 7a42343

Please sign in to comment.