{"record":{"id":"9f3d9d1eeb60c615","repo":"chatboxai/chatbox","slug":"name-must-be-an-integer","errorCode":null,"errorMessage":"--${name} must be an integer.","messagePattern":"--(.+?) must be an integer\\.","errorType":"validation","errorClass":"ChatboxCliUsageError","httpStatus":null,"severity":"warning","filePath":"src/renderer/packages/chatbox-cli/parser.ts","lineNumber":116,"sourceCode":"\nexport function stringFlag(parsed: ParsedArguments, name: string): string | undefined {\n  const value = parsed.flags.get(name)\n  return typeof value === 'string' ? value : undefined\n}\n\nexport function booleanFlag(parsed: ParsedArguments, name: string): boolean {\n  return parsed.flags.get(name) === true\n}\n\nexport function integerFlag(\n  parsed: ParsedArguments,\n  name: string,\n  options: { defaultValue: number; min: number; max: number }\n): number {\n  const value = parsed.flags.get(name)\n  if (value === undefined) return options.defaultValue\n  if (typeof value !== 'string' || !/^\\d+$/.test(value)) {\n    throw new ChatboxCliUsageError(`--${name} must be an integer.`)\n  }\n  const result = Number(value)\n  if (result < options.min || result > options.max) {\n    throw new ChatboxCliUsageError(`--${name} must be between ${options.min} and ${options.max}.`)\n  }\n  return result\n}\n","sourceCodeStart":98,"sourceCodeEnd":124,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/renderer/packages/chatbox-cli/parser.ts#L98-L124","documentation":"Thrown by integerFlag() in the Chatbox CLI argument parser when a flag's value is not a string matching ^\\d+$. This guards CLI integer options (e.g. numeric ports/thresholds) so downstream code receives a valid non-negative integer. Note the regex rejects negative numbers, decimals, and boolean-true (a bare --flag with no value), so all of those shapes trip this guard.","triggerScenarios":"Calling a CLI command whose definition uses integerFlag() and passing a non-digit value: `chatbox cmd --flag abc`, `chatbox cmd --flag 3.5`, `chatbox cmd --flag -1`, or `chatbox cmd --flag` (no value, parsed as boolean true). The check is `typeof value !== 'string' || !/^\\d+$/.test(value)`.","commonSituations":"User omits the value for an integer flag (parser stores true instead of a string); user passes a negative or fractional number expecting signed/decimal support; a downstream caller programmatically builds the argv string with an empty or NaN value.","solutions":["Pass a plain non-negative integer string for the flag, e.g. `--flag 42`.","If a bare flag with no value was intended, the command does not support that shape — supply an explicit integer.","If negative or decimal integers are genuinely needed, the regex in parser.ts:116 must be widened — file a change request; do not work around it client-side."],"exampleFix":"// before\nchatbox cmd --port\nchatbox cmd --limit -1\n\n// after\nchatbox cmd --port 8080\nchatbox cmd --limit 1","handlingStrategy":"validation","validationCode":"function assertCliInt(raw: unknown, name: string): void {\n  if (typeof raw !== 'string' || !/^\\d+$/.test(raw)) {\n    throw new Error(`Expected --${name} to be a non-negative integer string, got: ${String(raw)}`)\n  }\n}\n// run before invoking the command:\nassertCliInt(process.argv portValue, 'port')","typeGuard":"function isNonNegIntString(v: unknown): v is string {\n  return typeof v === 'string' && /^\\d+$/.test(v)\n}","tryCatchPattern":"try {\n  const port = integerFlag(parsed, 'port', { defaultValue: 8080, min: 1, max: 65535 })\n} catch (e) {\n  if (e instanceof ChatboxCliUsageError) {\n    // surface to the CLI user as a usage hint\n    console.error(e.message)\n    process.exit(2)\n  }\n  throw e\n}","preventionTips":["Always pair integerFlag usage with a visible --help min/max note.","Normalize bare flags to a default integer string before the parser sees them.","Test the CLI path with negative, decimal, and missing-value inputs."],"tags":["cli","validation","user-input","parser"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}