twentyhq/twenty · error · Error

Workspace count limit must be a number

Error message

Workspace count limit must be a number

What it means

Thrown by the CLI option parser for the `--workspace-count-limit` flag on the upgrade command. The parser runs parseInt(val); if the result is NaN it rejects the input before the command body runs. This is a commander-style @Option decorator's parse hook, so the throw surfaces as a CLI usage error during argument binding.

Source

Thrown at packages/twenty-server/src/database/commands/upgrade-version-command/upgrade.command.ts:99

    description:
      'Start from a specific workspace id. Workspaces are processed in ascending order of id.',
    required: false,
  })
  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,
      });

View on GitHub (pinned to 1f5dd2bbd2)

Solutions

  1. Pass a plain positive integer: `--workspace-count-limit 50`.
  2. If scripting, default unset variables: `--workspace-count-limit ${COUNT:-0}` is wrong (hits the <=0 guard); instead omit the flag entirely when unset.
  3. Validate the value in your wrapper script with a numeric check before forwarding it to the CLI.

Example fix

# before
npx nx run twenty-server:database:migrate:prod -- --workspace-count-limit all
# after
npx nx run twenty-server:database:migrate:prod -- --workspace-count-limit 50
Defensive patterns

Strategy: validation

Validate before calling

function parseWorkspaceCountLimitSafe(val: string | undefined): number | undefined {
  if (val == null || val === '') return undefined; // flag omitted
  if (!/^-?\d+$/.test(val)) {
    throw new Error(`--workspace-count-limit must be an integer, got: ${val}`);
  }
  return parseInt(val, 10);
}

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 a number') {
  console.error('Usage: --workspace-count-limit <positive-integer>, or omit to process all workspaces');
  process.exit(2);
  }
  throw err;
}

Prevention

When it happens

Trigger: Invoking the upgrade command with `--workspace-count-limit` set to a non-numeric string: empty string, alphabetic text (e.g. `--workspace-count-limit all`), a flag with no value where the shell passes `undefined`, or a value with trailing characters parseInt cannot parse to a finite number from the start.

Common situations: Operator typos (passing `--workspace-count-limit=10x`), scripting mistakes that interpolate an empty variable (`--workspace-count-limit $COUNT` when COUNT is unset → shell drops the arg or passes empty), or confusion with another flag's value format. Note parseInt('10x') === 10 so trailing junk after a leading number will NOT trip this — only fully non-numeric prefixes do.

Related errors


AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12). Data as JSON: /api/errors/0af83dda6fe677b7. Report an issue: GitHub.