{"record":{"id":"e57b9e3639dfdb10","repo":"can1357/oh-my-pi","slug":"expected-integer-for-name-got-raw","errorCode":null,"errorMessage":"Expected integer for --${name}, got \"${raw}\"","messagePattern":"Expected integer for --(.+?), got \"(.+?)\"","errorType":"validation","errorClass":"CliUsageError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/cli.ts","lineNumber":233,"sourceCode":"\t\t\t\t\tallowPositionals: true,\n\t\t\t\t\tstrict,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new CliUsageError(error instanceof Error ? error.message : String(error));\n\t\t\t}\n\t\t})();\n\n\t\t// Convert raw values to proper types and validate\n\t\tconst flags: Record<string, unknown> = {};\n\t\tfor (const [name, desc] of Object.entries(flagDefs)) {\n\t\t\tconst raw = rawValues[name];\n\t\t\tif (desc.kind === \"integer\") {\n\t\t\t\tif (raw === undefined || typeof raw === \"boolean\") {\n\t\t\t\t\tflags[name] = desc.default ?? undefined;\n\t\t\t\t} else {\n\t\t\t\t\tconst n = Number.parseInt(raw as string, 10);\n\t\t\t\t\tif (Number.isNaN(n)) {\n\t\t\t\t\t\tthrow new CliUsageError(`Expected integer for --${name}, got \"${raw}\"`);\n\t\t\t\t\t}\n\t\t\t\t\tflags[name] = n;\n\t\t\t\t}\n\t\t\t} else if (desc.kind === \"boolean\") {\n\t\t\t\tflags[name] =\n\t\t\t\t\traw !== undefined ? Boolean(raw) : desc.default !== undefined ? Boolean(desc.default) : undefined;\n\t\t\t} else {\n\t\t\t\t// string\n\t\t\t\tconst val = raw !== undefined && typeof raw !== \"boolean\" ? raw : (desc.default ?? undefined);\n\t\t\t\t// Validate options constraint\n\t\t\t\tif (val !== undefined && desc.options && !Array.isArray(val)) {\n\t\t\t\t\tif (!desc.options.includes(val as string)) {\n\t\t\t\t\t\tthrow new CliUsageError(\n\t\t\t\t\t\t\t`Expected --${name} to be one of: ${[...desc.options].join(\", \")}; got \"${val}\"`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tflags[name] = val;","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/cli.ts#L215-L251","documentation":"parse() validates flags declared with kind \"integer\": it parses the raw string with Number.parseInt and throws CliUsageError if the result is NaN. Only base-10 integer strings are accepted; anything else (letters, empty, float-with-unit) is rejected.","triggerScenarios":"Passing a non-integer value to an integer-typed flag, e.g. `--retries abc`, `--retries 1.5.0`, `--limit ''`, or `--concurrency 3s`.","commonSituations":"Typos in numeric flags, pasting values with units from docs (\"10m\"), or shell variables expanding to empty strings.","solutions":["Pass a plain base-10 integer, e.g. --retries 3.","Remove any unit suffix or whitespace from the value.","Quote values starting with '-' so the shell doesn't treat them as flags: --offset \"-5\".","Check the default in the flag definition if you intended to omit the flag entirely."],"exampleFix":"// before\ncli.parse(['--retries', 'three']); // CliUsageError\n// after\ncli.parse(['--retries', '3']);","handlingStrategy":"validation","validationCode":"const raw = String(flagValue);\nif (!/^-?\\d+$/.test(raw.trim())) {\n  throw new Error(`--retries must be an integer, got \"${raw}\"`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const { retries } = cli.parse(argv);\n} catch (err) {\n  if (err instanceof CliUsageError && err.message.startsWith('Expected integer')) {\n    console.error(err.message);\n    process.exitCode = 2;\n    return;\n  }\n  throw err;\n}","preventionTips":["Pass plain base-10 integers with no units or suffixes.","Quote negative numbers so shells don't parse them as flags.","Interpolate numeric shell variables safely: --retries \"${RETRIES}\"."],"tags":["cli","validation","argument-parsing"],"backgroundTag":"invalid-flag-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}