fix(cli): validate --batch/--limit on backfill-assets instead of silently producing NaN - #5180
Merged
Merged
Conversation
…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
enabled auto-merge (squash)
July 24, 2026 14:35
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug found by reading
apps/api/src/cli.ts(thebackfill-assetssubcommand) — not tied to an issue.--batchand--limitwere passed straight throughNumber(raw)with no validation (batch: values.batch ? Number(values.batch) : 500,limit: values.limit ? Number(values.limit) : undefined). A malformed value (e.g.--batch abcor--limit -1) silently becomesNaN, which then flows intorunPaged'sMath.min(batch, remaining)and Kysely's.limit(take)inbackfill-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 forSHUTDOWN_DRAIN_MS(#5177),NODE_ENV(#5173), and (in an open PR)DUCKDB_THREADS(#5130) inresolve-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 returnsundefinedwhen the flag is absent and throws a clearInvalid --batch "abc" — must be a positive integer.error otherwise.cli.tsnow calls it for both flags before invokingbackfillThreadAssetsCommand, catching and printing the error withprocess.exit(1)— matching the existing--targetvalidation style right above it in the same command block.Failure scenario before the fix:
deco backfill-assets --batch abcwould 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.tscovers 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.tsLocally 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
--batchand--limitin thebackfill-assetsCLI to fail fast on invalid input, preventing silentNaNvalues and confusing SQL errors. Users now get clear, early error messages; defaults remain unchanged.parsePositiveIntFlagto parse positive integers orundefined, throwingInvalid --<flag> "<value>" — must be a positive integer.on bad input.backfill-assetsand exit with code 1 on validation errors, matching existing--targetchecks.Written for commit 565a460. Summary will update on new commits.