{"record":{"id":"15bd85551cfa8e63","repo":"jackwener/OpenCLI","slug":"label-must-be-a-positive-integer-got-val","errorCode":null,"errorMessage":"--${label} must be a positive integer (got \"${val}\")","messagePattern":"--(.+?) must be a positive integer \\(got \"(.+?)\"\\)","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/cli.ts","lineNumber":764,"sourceCode":"  if (typeof targetId === 'string' && targetId.trim()) return targetId.trim();\n  const tab = opts instanceof Command ? opts.opts().tab : opts?.tab;\n  if (typeof tab === 'string' && tab.trim()) return tab.trim();\n  return undefined;\n}\n\nfunction parsePositiveIntOption(val: string | undefined, label: string, fallback: number): number {\n  if (val === undefined) return fallback;\n  const parsed = parseInt(val, 10);\n  if (Number.isNaN(parsed) || parsed <= 0) {\n    console.error(`[cli] Invalid ${label}=\"${val}\", using default ${fallback}`);\n    return fallback;\n  }\n  return parsed;\n}\n\nfunction parseScreenshotDim(val: string, label: string): number {\n  if (!/^\\d+$/.test(val)) {\n    throw new InvalidArgumentError(`--${label} must be a positive integer (got \"${val}\")`);\n  }\n  const parsed = parseInt(val, 10);\n  if (parsed <= 0) {\n    throw new InvalidArgumentError(`--${label} must be a positive integer (got \"${val}\")`);\n  }\n  return parsed;\n}\n\nfunction applyVerbose(opts: { verbose?: boolean }): void {\n  if (opts.verbose) process.env.OPENCLI_VERBOSE = '1';\n}\n\nfunction formatChildCommandSummary(command: Command): string {\n  return [...new Set(command.commands.map(child => child.name()))]\n    .sort((a, b) => a.localeCompare(b))\n    .join(', ');\n}\n","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/cli.ts#L746-L782","documentation":"Screenshot dimension options (e.g. --width/--height for screenshots) must be positive integers. parseScreenshotDim validates with /^\\d+$/ and throws a commander InvalidArgumentError when the value contains non-digit characters. This is the format-failure branch (the value must be a string of digits).","triggerScenarios":"Passing values like `--width 12.5`, `--width 100px`, `--width abc`, `--width ''`, or negative numbers like `--width -50` (the '-' fails the digit regex).","commonSituations":"Users appending units (px, %) to the value; copying CSS-style fractional sizes; shells interpreting a leading dash; pasting '1280,720' instead of two flags.","solutions":["Pass bare digits only: --width 1280 --height 720","Remove units or suffixes (px, %, rem)","Split comma-joined sizes into separate flags","Quote the value if your shell mangles it, but keep it digit-only"],"exampleFix":"// before\nopencli browser my-session screenshot --width 1280px\n// after\nopencli browser my-session screenshot --width 1280","handlingStrategy":"validation","validationCode":"function assertPositiveIntString(label: string, v: string): void {\n  if (!/^\\d+$/.test(v)) throw new Error(`--${label} must be a positive integer, got: ${JSON.stringify(v)}`);\n}\nassertPositiveIntString('width', widthArg);","typeGuard":"function isDigitString(v: string): boolean {\n  return /^\\d+$/.test(v);\n}","tryCatchPattern":"try {\n  await run(['opencli', 'browser', session, 'screenshot', '--width', w]);\n} catch (e) {\n  if (String((e as Error).message).includes('must be a positive integer')) {\n    console.error(`Bad dimension value: ${w}. Use bare positive integers, e.g. 1280.`);\n  }\n  throw e;\n}","preventionTips":["Pass bare digits only — no units (px, %), decimals, or thousands separators","When building flags programmatically, coerce with Number() and validate > 0 before stringifying","Keep width/height as separate flags rather than one combined value","Document dimension flags in script templates with example values"],"tags":["cli","validation","argument-parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}