{"record":{"id":"ed061c5d4e727f29","repo":"tinyhumansai/openhuman","slug":"label-must-be-a-positive-integer","errorCode":null,"errorMessage":"${label} must be a positive integer","messagePattern":"(.+?) must be a positive integer","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/debug/agent-prepare-context-audit.mjs","lineNumber":187,"sourceCode":"        break;\n      case \"--verbose\":\n        opts.verbose = true;\n        break;\n      case \"-h\":\n      case \"--help\":\n        console.log(usage());\n        process.exit(0);\n      default:\n        throw new Error(`unknown option: ${arg}`);\n    }\n  }\n  return opts;\n}\n\nfunction parsePositiveInt(raw, label) {\n  const value = Number(raw);\n  if (!Number.isInteger(value) || value < 1)\n    throw new Error(`${label} must be a positive integer`);\n  return value;\n}\n\nfunction defaultOpenhumanDir() {\n  if (process.env.OPENHUMAN_APP_ENV === \"staging\") {\n    return path.join(homedir(), \".openhuman-staging\");\n  }\n  if (process.env.OPENHUMAN_APP_ENV) {\n    return path.join(homedir(), \".openhuman\");\n  }\n  // APP_ENV unset: the core (launched from a shell that may export\n  // OPENHUMAN_APP_ENV=staging) and this script can disagree. Auto-pick the\n  // dir whose active_user.toml was touched most recently so transcript reads\n  // land in the same env the core actually uses. Falls back to prod.\n  const prod = path.join(homedir(), \".openhuman\");\n  const staging = path.join(homedir(), \".openhuman-staging\");\n  const mtime = (p) => {\n    try {","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/a221052e0df5b1f7598fceba7329fd1af95d6699/scripts/debug/agent-prepare-context-audit.mjs#L169-L205","documentation":"parsePositiveInt() in scripts/debug/agent-prepare-context-audit.mjs coerces a raw CLI string with Number() and rejects anything that is not an integer >= 1 — NaN (non-numeric text), 0, negatives, and fractional values all throw '<label> must be a positive integer'. It guards numeric options such as --max-print-chars and --rpc-timeout-ms before they can poison later math.","triggerScenarios":"Passing --rpc-timeout-ms 0, --max-print-chars 1.5, or a non-numeric value like --rpc-timeout-ms 10min. Number('') is 0, so an empty value also fails here — but an absent value fails earlier with 'missing value'.","commonSituations":"Trying to disable truncation with --max-print-chars 0; expressing timeouts in human units ('10m') the parser can't read; passing 0 expecting 'no timeout' when the semantics require >= 1.","solutions":["Pass a plain decimal integer >= 1, e.g. --rpc-timeout-ms 1200000","To raise limits, pick a larger value rather than 0 — 0 is intentionally invalid","For 'unbounded' printing, pass a very large --max-print-chars instead of 0"],"exampleFix":"# before\n$ node scripts/debug/agent-prepare-context-audit.mjs --max-print-chars 0\nError: --max-print-chars must be a positive integer\n\n# after\n$ node scripts/debug/agent-prepare-context-audit.mjs --max-print-chars 1000000","handlingStrategy":"validation","validationCode":"function assertPositiveInt(raw, label) {\n  const n = Number(raw);\n  if (!Number.isInteger(n) || n < 1) throw new Error(`${label} must be a positive integer (got ${raw})`);\n  return n;\n}\nconst rawTimeout = argv.find((_, i) => argv[i - 1] === \"--rpc-timeout-ms\") ?? \"600000\";\nassertPositiveInt(rawTimeout, \"--rpc-timeout-ms\");","typeGuard":"function isPositiveInt(raw) {\n  const n = Number(raw);\n  return Number.isInteger(n) && n >= 1;\n}","tryCatchPattern":null,"preventionTips":["Remember 0 is intentionally invalid — there is no 'disable' value for these options","Pass plain decimal integers; human units like 10m are not parsed","Encode the floor in wrapper scripts so bad values fail before the audit starts"],"tags":["cli","validation","arguments"],"backgroundTag":null,"analyzedSha":"a221052e0df5b1f7598fceba7329fd1af95d6699","analyzedAt":"2026-08-16T12:47:06.542Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}