{"record":{"id":"348820762b6d4bf7","repo":"jackwener/OpenCLI","slug":"label-must-be-a-positive-integer-348820","errorCode":null,"errorMessage":"${label} must be a positive integer","messagePattern":"(.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/codex/sidebar.js","lineNumber":32,"sourceCode":"    const label = normalizeMatch(project.project);\n    const projectPath = normalizeMatch(project.projectPath);\n    const needle = normalizeMatch(query);\n    if (!needle)\n        return true;\n    return label === needle\n        || label.includes(needle)\n        || projectPath === needle\n        || projectPath.endsWith(`/${needle}`);\n}\n\nexport function hasConversationTarget(kwargs) {\n    return !!(kwargs?.project || kwargs?.conversation || kwargs?.index || kwargs?.['thread-id']);\n}\n\nexport function parsePositiveIntegerOption(raw, label) {\n    const value = cleanText(raw);\n    if (!/^\\d+$/.test(value)) {\n        throw new ArgumentError(`${label} must be a positive integer`);\n    }\n    const parsed = Number.parseInt(value, 10);\n    if (!Number.isSafeInteger(parsed) || parsed < 1) {\n        throw new ArgumentError(`${label} must be a positive integer`);\n    }\n    return parsed;\n}\n\nexport function parseOptionalPositiveIntegerOption(raw, label) {\n    if (raw == null || cleanText(raw) === '') {\n        return null;\n    }\n    return parsePositiveIntegerOption(raw, label);\n}\n\nexport function requireNonEmptyOption(raw, label) {\n    const value = cleanText(raw);\n    if (!value) {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/codex/sidebar.js#L14-L50","documentation":"`parsePositiveIntegerOption` validates that an option value is a string of digits that parses to a safe integer >= 1. The first throw fires when the raw value fails the `/^\\d+$/` test — it contains non-digit characters (signs, spaces, decimals, letters) or is empty.","triggerScenarios":"Passing e.g. `--index 0x2`, `--index 1.5`, `--index -3`, `--index ' 4'`, `--index abc`, or an empty string to an option routed through `parsePositiveIntegerOption` (index, conversation, thread-id numeric paths).","commonSituations":"Users supply 0-based indices, decimal indices, or copy values with surrounding whitespace/currency of other formats; shell quoting yields empty strings.","solutions":["Pass a plain positive integer string, e.g. `--index 2` (1-based).","Trim whitespace and strip any non-digit characters from the value before calling.","Validate user input in your wrapper before forwarding options.","Use `parseOptionalPositiveIntegerOption` when the value may legitimately be absent."],"exampleFix":"// before\nparsePositiveIntegerOption('1.5', 'index'); // throws\n// after\nparsePositiveIntegerOption('2', 'index'); // OK","handlingStrategy":"validation","validationCode":"function isValidPositiveInt(v) {\n  return typeof v === 'string' && /^\\d+$/.test(v) && Number.isSafeInteger(Number(v)) && Number(v) >= 1;\n}\nif (!isValidPositiveInt(rawIndex)) throw new Error(`index must be a positive integer, got ${JSON.stringify(rawIndex)}`);","typeGuard":"const isPositiveIntOption = (v) => typeof v === 'string' && /^\\d+$/.test(v) && Number(v) >= 1 && Number.isSafeInteger(Number(v));","tryCatchPattern":"try {\n  await sidebarCmd({ index: raw });\n} catch (e) {\n  if (String(e.message).endsWith('must be a positive integer')) {\n    console.error(`Bad option value: ${JSON.stringify(raw)}; pass a 1-based integer like 2`);\n  } else throw e;\n}","preventionTips":["Pass plain digit strings, no signs, decimals, or whitespace.","Remember indices are 1-based, not 0-based.","Trim/normalize user input before forwarding options.","Use parseOptionalPositiveIntegerOption when the option is optional."],"tags":["validation","argument","codex","input"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}