--workers is silently clamped instead of rejected #10

Closed
opened 2026-08-09 03:44:20 +02:00 by clawbot · 2 comments
Collaborator

scan.go:54-56 does if workers < 1 { workers = 1 }, and main.go:71-72 registers the flag with no validation. So --workers 0 and --workers -8 — both plain typos — quietly run the whole scan single-threaded.

On a 150 TB pool that is the difference between a scan finishing overnight and a scan still running the next afternoon, with nothing on stderr to explain why. README §Error handling defines exit 2 for usage errors, which is what a nonsensical flag value is.

Definition of done

  1. scan rejects --workers less than 1 with a one-line usage error on stderr and exit 2.
  2. The clamp in scan.go:54-56 is removed, since the value is now validated upstream.
  3. README §scan mode documents the constraint and states the default is runtime.NumCPU().
  4. A CLI test asserts exit 2 and the message for --workers 0 and --workers -1.
  5. make check green.
`scan.go:54-56` does `if workers < 1 { workers = 1 }`, and `main.go:71-72` registers the flag with no validation. So `--workers 0` and `--workers -8` — both plain typos — quietly run the whole scan single-threaded. On a 150 TB pool that is the difference between a scan finishing overnight and a scan still running the next afternoon, with nothing on stderr to explain why. README §Error handling defines exit 2 for usage errors, which is what a nonsensical flag value is. ## Definition of done 1. `scan` rejects `--workers` less than 1 with a one-line usage error on stderr and exit 2. 2. The clamp in `scan.go:54-56` is removed, since the value is now validated upstream. 3. README §scan mode documents the constraint and states the default is `runtime.NumCPU()`. 4. A CLI test asserts exit 2 and the message for `--workers 0` and `--workers -1`. 5. `make check` green.
clawbot added this to the 1.0.0 milestone 2026-08-09 03:44:20 +02:00
Author
Collaborator

Plan (implementer's brief). The clamp now lives at the top of runScan in scan.go. Validate --workers where the flag is parsed, so a value below 1 is a usage error: one line on stderr, exit 2, through the same path the other usage errors take in run. Then remove the clamp. README.md §scan mode states the constraint and the default (runtime.NumCPU()). Tests per the definition of done.

Model: opus-5-5

Plan (implementer's brief). The clamp now lives at the top of `runScan` in `scan.go`. Validate `--workers` where the flag is parsed, so a value below 1 is a usage error: one line on stderr, exit 2, through the same path the other usage errors take in `run`. Then remove the clamp. `README.md` §scan mode states the constraint and the default (`runtime.NumCPU()`). Tests per the definition of done. Model: opus-5-5
clawbot self-assigned this 2026-10-04 12:02:36 +02:00
Author
Collaborator

Implemented in #86: scan --workers below 1 now exits 2 with a one-line error on stderr, and the clamp in runScan is removed.

Model: opus-5-5

Implemented in https://git.eeqj.de/sneak/sfdupes/pulls/86: `scan --workers` below 1 now exits 2 with a one-line error on stderr, and the clamp in `runScan` is removed. Model: opus-5-5
Sign in to join this conversation.