{"record":{"id":"7447d230c5fd3f17","repo":"abhigyanpatwari/GitNexus","slug":"flag-must-be-a-positive-integer-7447d2","errorCode":null,"errorMessage":"${flag} must be a positive integer","messagePattern":"(.+?) must be a positive integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/cli/watch.ts","lineNumber":89,"sourceCode":"  readonly maxFileSize: string | undefined;\n  readonly workerTimeout: string | undefined;\n  readonly verbose: string | undefined;\n}\n\nfunction setEnvironment(name: string, value: string | undefined): void {\n  if (value === undefined) delete process.env[name];\n  else process.env[name] = value;\n}\n\nfunction positiveInteger(\n  value: string | undefined,\n  flag: string,\n  maximum?: number,\n): number | undefined {\n  if (value === undefined) return undefined;\n  const parsed = Number(value);\n  if (!Number.isInteger(parsed) || parsed < 1)\n    throw new Error(`${flag} must be a positive integer`);\n  if (maximum !== undefined && parsed > maximum) {\n    throw new Error(`${flag} must not exceed ${maximum}`);\n  }\n  return parsed;\n}\n\nexport async function resolveWatchOptions(\n  repoPath: string,\n  cli: WatchCliOptions,\n  baseline: WatchEnvironmentBaseline,\n  reportIgnoredConfig: (names: readonly string[]) => void = () => {},\n): Promise<CoreAnalyzeOptions> {\n  const config = (await loadAnalyzeConfigStrict(repoPath)) ?? {};\n  const merged = mergeAnalyzeOptions(cli, config);\n  const unsupported = [\n    ['--force', cli.force],\n    ['--repair-fts', cli.repairFts],\n    ['--embeddings', cli.embeddings],","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/52924ef12c2290ceee4612526a828ec4cdf2047f/gitnexus/src/cli/watch.ts#L71-L107","documentation":"Thrown by the positiveInteger flag parser in watch.ts when a numeric CLI flag for `analyze --watch` (worker pool size, worker timeout seconds, max file size, etc.) is not an integer >= 1. The value is coerced with Number(), so non-numeric strings, decimals, zero, and negative numbers all fail.","triggerScenarios":"Passing e.g. `--worker-pool-size 0`, `--worker-timeout-seconds 2.5`, `--max-file-size abc`, `--max-file-size -1`, or an empty value to analyze --watch; also when a wrapper script forwards a blank/unset variable as the flag value.","commonSituations":"Typos in shell scripts (`SIZE=${SIZE}` with SIZE empty), pasting values with units ('10mb' instead of byte counts), using fractional seconds, or confusing 0-based with 1-based minimums.","solutions":["Pass a whole number >= 1 for the flag, e.g. `--worker-pool-size 4`, `--max-file-size 5242880`.","Strip units and convert to the expected unit (bytes for max-file-size, seconds for timeout) before invoking the CLI.","Fix the shell script so empty variables are defaulted: `SIZE=${SIZE:-4}`.","Validate inputs in your wrapper (integer check) before exec'ing the gitnexus CLI."],"exampleFix":"// before\ngitnexus analyze --watch --worker-timeout-seconds 1.5\n\n// after\ngitnexus analyze --watch --worker-timeout-seconds 2","handlingStrategy":"validation","validationCode":"function assertPositiveInt(value: string | number | undefined, flag: string): number | undefined {\n  if (value === undefined) return undefined;\n  const n = Number(value);\n  if (!Number.isInteger(n) || n < 1) throw new Error(`${flag} must be a positive integer, got ${value}`);\n  return n;\n}\n// call before spawning: assertPositiveInt(process.env.WORKERS, '--worker-pool-size')","typeGuard":"function isPositiveInt(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 1;\n}","tryCatchPattern":"try {\n  await runWatchCommand(argv);\n} catch (e) {\n  if (/(must be a positive integer|must not exceed)/.test(e.message)) {\n    console.error(`Bad flag value: ${e.message} — see gitnexus analyze --help`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Default numeric env vars in wrapper scripts: SIZE=${SIZE:-4}.","Convert units (MB -> bytes) explicitly at the call site and never pass strings with units.","Add a shell pre-check: case \"$V\" in ''|*[!0-9]*) abort;; esac for integer flags."],"tags":["cli","argument-validation","watch-mode","flags"],"backgroundTag":"invalid-cli-argument","analyzedSha":"52924ef12c2290ceee4612526a828ec4cdf2047f","analyzedAt":"2026-09-01T13:15:02.810Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}