From 136283b01e2f2dac92908c232243c5bfc61e27b1 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Wed, 14 Aug 2024 23:42:04 -0400 Subject: [PATCH] remove: fix issue removing dynamic resource (fetch failed) --- cmd/sst/cli/project.go | 3 --- cmd/sst/deploy.go | 1 + cmd/sst/diff.go | 1 + cmd/sst/main.go | 4 ++-- cmd/sst/refresh.go | 1 + cmd/sst/remove.go | 6 ++++-- pkg/project/stack.go | 18 ++++++++++++++++++ 7 files changed, 27 insertions(+), 7 deletions(-) diff --git a/cmd/sst/cli/project.go b/cmd/sst/cli/project.go index 9b384f09e..0a9ce2412 100644 --- a/cmd/sst/cli/project.go +++ b/cmd/sst/cli/project.go @@ -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{ diff --git a/cmd/sst/deploy.go b/cmd/sst/deploy.go index 9e1df0b84..e212a475c 100644 --- a/cmd/sst/deploy.go +++ b/cmd/sst/deploy.go @@ -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 diff --git a/cmd/sst/diff.go b/cmd/sst/diff.go index ff0e13f3c..e5c2fc028 100644 --- a/cmd/sst/diff.go +++ b/cmd/sst/diff.go @@ -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 diff --git a/cmd/sst/main.go b/cmd/sst/main.go index bc2a7b2b8..cfab6d8bc 100644 --- a/cmd/sst/main.go +++ b/cmd/sst/main.go @@ -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 @@ -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", diff --git a/cmd/sst/refresh.go b/cmd/sst/refresh.go index 1bc8d8616..158d53250 100644 --- a/cmd/sst/refresh.go +++ b/cmd/sst/refresh.go @@ -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 diff --git a/cmd/sst/remove.go b/cmd/sst/remove.go index 89069d6d0..f0bd23c81 100644 --- a/cmd/sst/remove.go +++ b/cmd/sst/remove.go @@ -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 diff --git a/pkg/project/stack.go b/pkg/project/stack.go index 1087910b5..478dda990 100644 --- a/pkg/project/stack.go +++ b/pkg/project/stack.go @@ -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" @@ -43,6 +44,7 @@ type StackInput struct { Target []string ServerPort int Dev bool + Verbose bool } type ConcurrentUpdateEvent struct{} @@ -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), @@ -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(), @@ -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), @@ -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),