Skip to content

Commit c327213

Browse files
greynewellclaude
andcommitted
fix: add --timeout flag to dead-code command (default 7200s)
Without a timeout, the polling loop ran indefinitely if an API job got stuck. --timeout wraps the command context with a deadline so the CLI exits cleanly with a clear error message. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 893dddd commit c327213

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

cmd/deadcode.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package cmd
22

33
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
48
"github.com/spf13/cobra"
59

610
"github.com/supermodeltools/cli/internal/config"
@@ -33,7 +37,19 @@ explanations for why each function was flagged.`,
3337
if len(args) > 0 {
3438
dir = args[0]
3539
}
36-
return deadcode.Run(cmd.Context(), cfg, dir, opts)
40+
ctx := cmd.Context()
41+
if opts.Timeout > 0 {
42+
var cancel context.CancelFunc
43+
ctx, cancel = context.WithTimeout(ctx, time.Duration(opts.Timeout)*time.Second)
44+
defer cancel()
45+
}
46+
if err := deadcode.Run(ctx, cfg, dir, opts); err != nil {
47+
if ctx.Err() == context.DeadlineExceeded {
48+
return fmt.Errorf("analysis timed out after %ds (increase with --timeout)", opts.Timeout)
49+
}
50+
return err
51+
}
52+
return nil
3753
},
3854
}
3955

@@ -42,6 +58,7 @@ explanations for why each function was flagged.`,
4258
c.Flags().IntVar(&opts.Limit, "limit", 0, "maximum number of candidates to return")
4359
c.Flags().StringArrayVar(&opts.Ignore, "ignore", nil, "glob pattern to exclude from results (repeatable, supports **)")
4460
c.Flags().StringVarP(&opts.Output, "output", "o", "", "output format: human|json")
61+
c.Flags().IntVar(&opts.Timeout, "timeout", 7200, "maximum seconds to wait for analysis (0 = no limit)")
4562

4663
rootCmd.AddCommand(c)
4764
}

internal/deadcode/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Options struct {
1919
MinConfidence string // "high" | "medium" | "low"
2020
Limit int // max candidates to return; 0 = all
2121
Ignore []string // glob patterns to exclude (supports **)
22+
Timeout int // max seconds; 0 = no limit (context deadline applied by cmd layer)
2223
}
2324

2425
// Run uploads the repo and runs dead code analysis via the dedicated API endpoint.

0 commit comments

Comments
 (0)