Skip to content

Commit 2d88fbd

Browse files
committed
fix(cmd): keep runToolMultiService under the gocyclo budget
Making runToolFromCSV return an error (so the CSV purchase path is unit-testable) added an `if err != nil { log.Fatalf }` branch to runToolMultiService, pushing its cyclomatic complexity from 10 to 11 and tripping the gocyclo pre-commit hook (over 10). Extract the error-to-fatal glue into runCSVPathOrFatal so the entrypoint drops back to complexity 10 while runToolFromCSV keeps its testable error return.
1 parent b0330f7 commit 2d88fbd

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎cmd/multi_service.go‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ var shutdownRequested atomic.Bool
7676
// (2) score, display, confirm, and purchase.
7777
func runToolMultiService(ctx context.Context, cfg Config) {
7878
if cfg.CSVInput != "" {
79-
if err := runToolFromCSV(ctx, cfg); err != nil {
80-
log.Fatalf("%v", err)
81-
}
79+
runCSVPathOrFatal(ctx, cfg)
8280
return
8381
}
8482

@@ -258,9 +256,19 @@ func buildServiceStats(recs []common.Recommendation, results []common.PurchaseRe
258256
return stats
259257
}
260258

259+
// runCSVPathOrFatal runs the CSV purchase path and exits fatally on error.
260+
// It isolates the error-to-fatal glue from runToolMultiService so that path
261+
// stays under the cyclomatic-complexity budget while runToolFromCSV remains
262+
// unit-testable via its returned error.
263+
func runCSVPathOrFatal(ctx context.Context, cfg Config) {
264+
if err := runToolFromCSV(ctx, cfg); err != nil {
265+
log.Fatalf("%v", err)
266+
}
267+
}
268+
261269
// runToolFromCSV processes recommendations from a CSV input file.
262270
// It returns an error instead of exiting so the orchestration glue is
263-
// unit-testable; the caller (runToolMultiService) turns errors fatal.
271+
// unit-testable; the caller (runCSVPathOrFatal) turns errors fatal.
264272
func runToolFromCSV(ctx context.Context, cfg Config) error {
265273
// Determine if this is a dry run
266274
isDryRun := !cfg.ActualPurchase

0 commit comments

Comments
 (0)