Skip to content

fix(cli): validate --batch/--limit on backfill-assets instead of silently producing NaN - #5180

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/backfill-assets-validate-batch-limit-w3
Jul 24, 2026
Merged

fix(cli): validate --batch/--limit on backfill-assets instead of silently producing NaN#5180
pedrofrxncx merged 1 commit into
mainfrom
fix/backfill-assets-validate-batch-limit-w3

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Bug found by reading apps/api/src/cli.ts (the backfill-assets subcommand) — not tied to an issue.

--batch and --limit were passed straight through Number(raw) with no validation (batch: values.batch ? Number(values.batch) : 500, limit: values.limit ? Number(values.limit) : undefined). A malformed value (e.g. --batch abc or --limit -1) silently becomes NaN, which then flows into runPaged's Math.min(batch, remaining) and Kysely's .limit(take) in backfill-assets.ts — producing a confusing SQL-level error deep in the DB layer instead of a clear CLI message at the entry point. This is the same bug class already fixed for SHUTDOWN_DRAIN_MS (#5177), NODE_ENV (#5173), and (in an open PR) DUCKDB_THREADS (#5130) in resolve-config.ts — this one just lives in the CLI flag parser instead of the settings pipeline.

Fix: extracted a small pure parsePositiveIntFlag(flag, raw) helper (apps/api/src/cli/parse-positive-int-flag.ts) that returns undefined when the flag is absent and throws a clear Invalid --batch "abc" — must be a positive integer. error otherwise. cli.ts now calls it for both flags before invoking backfillThreadAssetsCommand, catching and printing the error with process.exit(1) — matching the existing --target validation style right above it in the same command block.

Failure scenario before the fix: deco backfill-assets --batch abc would run past argument parsing and fail later with a raw SQL/driver error instead of telling the user their flag was invalid. Regression test: apps/api/src/cli/parse-positive-int-flag.test.ts covers the missing-flag, valid-value, non-numeric, zero/negative, and non-integer cases.

Reviewer check: bun test apps/api/src/cli/parse-positive-int-flag.test.ts

Locally verified: bun run fmt, cd apps/api && bunx tsc --noEmit, and the targeted test file above all pass. Full CI covers the rest.


Summary by cubic

Validate --batch and --limit in the backfill-assets CLI to fail fast on invalid input, preventing silent NaN values and confusing SQL errors. Users now get clear, early error messages; defaults remain unchanged.

  • Bug Fixes
    • Added parsePositiveIntFlag to parse positive integers or undefined, throwing Invalid --<flag> "<value>" — must be a positive integer. on bad input.
    • Applied it to backfill-assets and exit with code 1 on validation errors, matching existing --target checks.
    • Added unit tests covering missing flag, valid value, non-numeric, zero/negative, and non-integer cases.

Written for commit 565a460. Summary will update on new commits.

Review in cubic

…ntly producing NaN

--batch and --limit were passed straight through Number(raw) with no
validation. A malformed value (e.g. --batch abc) becomes NaN and flows into
runPaged's Math.min(batch, remaining) and Kysely's .limit(take), producing a
confusing SQL-level error instead of a clear CLI message — same class of bug
already fixed for SHUTDOWN_DRAIN_MS/NODE_ENV/DUCKDB_THREADS in resolve-config.ts.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 24, 2026 14:35
@pedrofrxncx
pedrofrxncx merged commit d7c008a into main Jul 24, 2026
14 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/backfill-assets-validate-batch-limit-w3 branch July 24, 2026 14:43
decocms Bot pushed a commit that referenced this pull request Jul 24, 2026
PR: #5180 fix(cli): validate --batch/--limit on backfill-assets instead of silently producing NaN
Bump type: patch

- decocms (apps/api/package.json): 4.122.10 -> 4.122.11

Deploy-Scope: server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant