{"record":{"id":"e0ee1dbf3e0aba5e","repo":"twentyhq/twenty","slug":"workspace-count-limit-must-be-greater-than-0","errorCode":null,"errorMessage":"Workspace count limit must be greater than 0","messagePattern":"Workspace count limit must be greater than 0","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/upgrade.command.ts","lineNumber":103,"sourceCode":"  parseStartFromWorkspaceId(val: string): string {\n    return val;\n  }\n\n  @Option({\n    flags: '--workspace-count-limit [count]',\n    description:\n      'Limit the number of workspaces to process. Workspaces are processed in ascending order of id.',\n    required: false,\n  })\n  parseWorkspaceCountLimit(val: string): number {\n    const limit = parseInt(val);\n\n    if (isNaN(limit)) {\n      throw new Error('Workspace count limit must be a number');\n    }\n\n    if (limit <= 0) {\n      throw new Error('Workspace count limit must be greater than 0');\n    }\n\n    return limit;\n  }\n\n  override async run(\n    _passedParams: string[],\n    options: RawUpgradeCommandOptions,\n  ): Promise<void> {\n    if (options.verbose) {\n      this.logger = new CommandLogger({\n        verbose: true,\n        constructorName: this.constructor.name,\n      });\n    }\n\n    if (\n      isDefined(options.workspaceId) &&","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/upgrade.command.ts#L85-L121","documentation":"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.","triggerScenarios":"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`).","commonSituations":"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.","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."],"exampleFix":"# before\nnpx nx run twenty-server:database:migrate:prod -- --workspace-count-limit 0\n# after (process all workspaces — just omit the flag)\nnpx nx run twenty-server:database:migrate:prod","handlingStrategy":"validation","validationCode":"function parseWorkspaceCountLimitSafe(val: string | undefined): number | undefined {\n  if (val == null || val === '') return undefined;\n  const n = parseInt(val, 10);\n  if (Number.isNaN(n)) throw new Error('--workspace-count-limit must be an integer');\n  if (n <= 0) throw new Error('--workspace-count-limit must be greater than 0');\n  return n;\n}","typeGuard":"function isPositiveIntegerString(val: string): boolean {\n  return /^\\d+$/.test(val) && parseInt(val, 10) > 0;\n}","tryCatchPattern":"try {\n  await upgrade.run([], options);\n} catch (err) {\n  if (err instanceof Error && err.message === 'Workspace count limit must be greater than 0') {\n  console.error('Pass a positive integer, or omit --workspace-count-limit to process all workspaces');\n  process.exit(2);\n  }\n  throw err;\n}","preventionTips":["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."],"tags":["cli","argument-validation","upgrade-command"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}