twentyhq/twenty · error · Error
Workspace count limit must be greater than 0
Error message
Workspace count limit must be greater than 0
What it means
Thrown by the same parseWorkspaceCountLimit @Option parser, after the NaN check. Once parseInt succeeds it enforces limit > 0; zero or negative integers are rejected. This prevents the downstream pagination logic (which slices workspaces into batches of `limit`) from producing an empty or infinite loop.
Source
Thrown at packages/twenty-server/src/database/commands/upgrade-version-command/upgrade.command.ts:103
parseStartFromWorkspaceId(val: string): string {
return val;
}
@Option({
flags: '--workspace-count-limit [count]',
description:
'Limit the number of workspaces to process. Workspaces are processed in ascending order of id.',
required: false,
})
parseWorkspaceCountLimit(val: string): number {
const limit = parseInt(val);
if (isNaN(limit)) {
throw new Error('Workspace count limit must be a number');
}
if (limit <= 0) {
throw new Error('Workspace count limit must be greater than 0');
}
return limit;
}
override async run(
_passedParams: string[],
options: RawUpgradeCommandOptions,
): Promise<void> {
if (options.verbose) {
this.logger = new CommandLogger({
verbose: true,
constructorName: this.constructor.name,
});
}
if (
isDefined(options.workspaceId) &&View on GitHub (pinned to 1f5dd2bbd2)
Solutions
- To process all workspaces, omit `--workspace-count-limit` entirely.
- To limit processing, pass a positive integer: `--workspace-count-limit 1`.
- If you genuinely meant 'all', remove the flag from your automation rather than passing 0.
Example fix
# before npx nx run twenty-server:database:migrate:prod -- --workspace-count-limit 0 # after (process all workspaces — just omit the flag) npx nx run twenty-server:database:migrate:prod
Defensive patterns
Strategy: validation
Validate before calling
function parseWorkspaceCountLimitSafe(val: string | undefined): number | undefined {
if (val == null || val === '') return undefined;
const n = parseInt(val, 10);
if (Number.isNaN(n)) throw new Error('--workspace-count-limit must be an integer');
if (n <= 0) throw new Error('--workspace-count-limit must be greater than 0');
return n;
} Type guard
function isPositiveIntegerString(val: string): boolean {
return /^\d+$/.test(val) && parseInt(val, 10) > 0;
} Try / catch
try {
await upgrade.run([], options);
} catch (err) {
if (err instanceof Error && err.message === 'Workspace count limit must be greater than 0') {
console.error('Pass a positive integer, or omit --workspace-count-limit to process all workspaces');
process.exit(2);
}
throw err;
} Prevention
- Omit the flag entirely when you want all workspaces — do not use 0 as a sentinel.
- In automation, guard the value with a numeric-and-positive check before invoking the CLI.
- Keep a single source of truth for the limit in your orchestration so it cannot go negative.
When it happens
Trigger: Passing `--workspace-count-limit 0`, a negative number (`--workspace-count-limit -1`), or a value that parseInt coerces to zero (e.g. `--workspace-count-limit 0abc`).
Common situations: Operators who use 0 expecting 'no limit' (the flag has no such convention — omit it instead), copy-paste from another tool's semantics, or shell expansion of an arithmetic expression that underflows to zero.
Related errors
- Workspace count limit must be a number
- Directory ${appDirectory} already exists and is not empty
- Missing env var: ${name}
- Standard application is missing messageList view ${LIST_VIEW
- Failed to create searchVector GIN index(es) for workspace ${
AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12).
Data as JSON: /api/errors/e0ee1dbf3e0aba5e.
Report an issue: GitHub.