diff --git a/cmd/root/root.go b/cmd/root/root.go index cd594e490..a97b61160 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -311,7 +311,9 @@ func isFirstRun() bool { if err != nil { return false // File already exists or other error, not first run } - f.Close() + if err := f.Close(); err != nil { + slog.Warn("Failed to close first run marker file", "error", err) + } return true } diff --git a/cmd/root/run.go b/cmd/root/run.go index 9cf76fad1..cf98f3879 100644 --- a/cmd/root/run.go +++ b/cmd/root/run.go @@ -142,11 +142,12 @@ func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []s if err != nil { return fmt.Errorf("failed to create CPU profile: %w", err) } - defer pf.Close() if err := pprof.StartCPUProfile(pf); err != nil { + pf.Close() return fmt.Errorf("failed to start CPU profile: %w", err) } defer pprof.StopCPUProfile() + defer pf.Close() slog.Info("CPU profiling enabled", "file", f.cpuProfile) }