Skip to content

Commit 5039a4e

Browse files
committed
fix: move recording proxy cleanup defer out of if/else block
The defer for recordCleanup was inside an else block, which meant it was scoped to that block only. Restructure to declare variables first, check the error, then defer cleanup unconditionally - matching the pattern already used in run.go. Fixes #1980 Fixes #1987 Assisted-By: docker-agent
1 parent 1f2980b commit 5039a4e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

cmd/root/api.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ func (f *apiFlags) runAPICommand(cmd *cobra.Command, args []string) error {
7171
}()
7272

7373
// Start recording proxy if --record is specified
74-
if _, recordCleanup, err := setupRecordingProxy(f.recordPath, &f.runConfig); err != nil {
74+
_, recordCleanup, err := setupRecordingProxy(f.recordPath, &f.runConfig)
75+
if err != nil {
7576
return err
76-
} else {
77-
defer func() {
78-
if err := recordCleanup(); err != nil {
79-
slog.Error("Failed to cleanup recording proxy", "error", err)
80-
}
81-
}()
8277
}
78+
defer func() {
79+
if err := recordCleanup(); err != nil {
80+
slog.Error("Failed to cleanup recording proxy", "error", err)
81+
}
82+
}()
8383

8484
if f.pullIntervalMins > 0 && !config.IsOCIReference(agentsPath) {
8585
return fmt.Errorf("--pull-interval flag can only be used with OCI references, not local files")

0 commit comments

Comments
 (0)