Skip to content

Commit

Permalink
remove: fix issue removing dynamic resource (fetch failed)
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Aug 15, 2024
1 parent 52b649a commit 136283b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
3 changes: 0 additions & 3 deletions cmd/sst/cli/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ func (c *Cli) InitProject() (*project.Project, error) {

func (c *Cli) configureLog() {
writers := []io.Writer{logFile}
if c.Bool("verbose") {
writers = append(writers, os.Stderr)
}
writer := io.MultiWriter(writers...)
slog.SetDefault(
slog.New(slog.NewTextHandler(writer, &slog.HandlerOptions{
Expand Down
1 change: 1 addition & 0 deletions cmd/sst/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func CmdDeploy(c *cli.Cli) error {
Command: "deploy",
Target: target,
ServerPort: s.Port,
Verbose: c.Bool("verbose"),
})
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/sst/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func CmdDiff(c *cli.Cli) error {
ServerPort: s.Port,
Dev: c.Bool("dev"),
Target: target,
Verbose: c.Bool("verbose"),
})
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/sst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() {
}
} else {
slog.Error("exited with error", "err", err)
ui.Error("Unexpected error occurred. Please check the logs or run with --verbose for more details.")
ui.Error("Unexpected error occurred. Please check the logs in .sst/log/sst.log")
}
os.Exit(1)
return
Expand Down Expand Up @@ -228,7 +228,7 @@ var root = &cli.Command{
Short: "Enable verbose logging",
Long: strings.Join([]string{
"",
"Enables verbose logging for the CLI output.",
"Enables verbose logging that includes extra information in logs.",
"",
"```bash",
"sst [command] --verbose",
Expand Down
1 change: 1 addition & 0 deletions cmd/sst/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func CmdRefresh(c *cli.Cli) error {
Command: "refresh",
Target: target,
ServerPort: s.Port,
Verbose: c.Bool("verbose"),
})
if err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions cmd/sst/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ func CmdRemove(c *cli.Cli) error {
defer ui.Destroy()
defer c.Cancel()
err = p.Run(c.Context, &project.StackInput{
Command: "remove",
Target: target,
Command: "remove",
Target: target,
ServerPort: s.Port,
Verbose: c.Bool("verbose"),
})
if err != nil {
return err
Expand Down
18 changes: 18 additions & 0 deletions pkg/project/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/nrednav/cuid2"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/pulumi/pulumi/sdk/v3/go/auto/debug"
"github.com/pulumi/pulumi/sdk/v3/go/auto/events"
"github.com/pulumi/pulumi/sdk/v3/go/auto/optdestroy"
"github.com/pulumi/pulumi/sdk/v3/go/auto/optpreview"
Expand All @@ -43,6 +44,7 @@ type StackInput struct {
Target []string
ServerPort int
Dev bool
Verbose bool
}

type ConcurrentUpdateEvent struct{}
Expand Down Expand Up @@ -621,9 +623,22 @@ func (p *Project) Run(ctx context.Context, input *StackInput) error {
}
}()

debugLogging := debug.LoggingOptions{}
if input.Verbose {
slog.Info("enabling verbose logging")
logLevel := uint(11)
debugLogging = debug.LoggingOptions{
LogLevel: &logLevel,
FlowToPlugins: true,
Debug: true,
Tracing: "file://" + filepath.Join(p.PathWorkingDir(), "log", "trace.json"),
}
}

switch input.Command {
case "deploy":
result, derr := stack.Up(ctx,
optup.DebugLogging(debugLogging),
optup.Target(input.Target),
optup.TargetDependents(),
optup.ProgressStreams(pulumiLog),
Expand All @@ -635,6 +650,7 @@ func (p *Project) Run(ctx context.Context, input *StackInput) error {

case "remove":
result, derr := stack.Destroy(ctx,
optdestroy.DebugLogging(debugLogging),
optdestroy.ContinueOnError(),
optdestroy.Target(input.Target),
optdestroy.TargetDependents(),
Expand All @@ -647,6 +663,7 @@ func (p *Project) Run(ctx context.Context, input *StackInput) error {

case "refresh":
result, derr := stack.Refresh(ctx,
optrefresh.DebugLogging(debugLogging),
optrefresh.Target(input.Target),
optrefresh.ProgressStreams(pulumiLog),
optrefresh.ErrorProgressStreams(pulumiErrWriter),
Expand All @@ -656,6 +673,7 @@ func (p *Project) Run(ctx context.Context, input *StackInput) error {
summary = result.Summary
case "diff":
_, derr := stack.Preview(ctx,
optpreview.DebugLogging(debugLogging),
optpreview.Diff(),
optpreview.Target(input.Target),
optpreview.ProgressStreams(pulumiLog),
Expand Down

0 comments on commit 136283b

Please sign in to comment.