{"record":{"id":"05d4347a5d3123e9","repo":"can1357/oh-my-pi","slug":"invalid-max-time-value-json-stringify-value","errorCode":null,"errorMessage":"Invalid --max-time value: ${JSON.stringify(value)}. Expected a positive number of seconds or duration like \"5s\", \"10m\", \"1h\".","messagePattern":"Invalid --max-time value: (.+?)\\. Expected a positive number of seconds or duration like \"5s\", \"10m\", \"1h\"\\.","errorType":"validation","errorClass":"CliUsageError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/flag-tables.ts","lineNumber":102,"sourceCode":"\nconst setResume: OptionalSetter = (result, value) => {\n\tresult.resume = value !== undefined ? value : true;\n};\n\nconst MAX_TIME_DURATION_RE = /^(\\d+(?:\\.\\d+)?)([smh])$/;\n\nfunction maxTimeMultiplier(unit: string | undefined): number {\n\tif (unit === \"h\") return 3600;\n\tif (unit === \"m\") return 60;\n\treturn 1;\n}\n\nfunction parseMaxTimeSeconds(value: string): number {\n\tconst trimmed = value.trim();\n\tconst duration = MAX_TIME_DURATION_RE.exec(trimmed);\n\tconst seconds = duration ? Number(duration[1]) * maxTimeMultiplier(duration[2]) : Number(trimmed);\n\tif (Number.isFinite(seconds) && seconds > 0) return seconds;\n\tthrow new CliUsageError(\n\t\t`Invalid --max-time value: ${JSON.stringify(value)}. Expected a positive number of seconds or duration like \"5s\", \"10m\", \"1h\".`,\n\t);\n}\n\n/**\n * Setters for flags with string values. Most built-ins consume the next argv\n * token even when it starts with `-`; flags listed in\n * {@link EXTENSION_SHADOWABLE_STRING_FLAGS} use extension-style consumption so\n * a registered boolean extension can shadow them before profile bootstrap.\n */\nexport const STRING_SETTERS: Record<string, StringSetter> = {\n\t\"--cwd\": (result, value) => {\n\t\tresult.cwd = value;\n\t},\n\t\"--config\": (result, value) => {\n\t\tresult.config = [...(result.config ?? []), value];\n\t},\n\t\"--add-dir\": (result, value) => {","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/flag-tables.ts#L84-L120","documentation":"parseMaxTimeSeconds (used by the --max-time flag setter in flag-tables.ts) accepts a positive number of seconds or a duration like 5s/10m/1h. Anything else — non-numeric text, zero, negative, NaN, or unsupported units — raises this CliUsageError before the command runs.","triggerScenarios":"`--max-time abc`, `--max-time 0`, `--max-time -5`, `--max-time 5x` (unknown unit), `--max-time 5 s` (space inside duration), or `--max-time ''` (empty string).","commonSituations":"Users assuming milliseconds (`--max-time 30000` is 30000 s, not 30 s — that parses but note units), writing `5sec` or `5min` which don't match the duration regex, or shells splitting `5s` and losing it so the flag receives an empty/garbage value.","solutions":["Use a plain positive number of seconds: --max-time 30","Or use a supported duration suffix: --max-time 5s, --max-time 10m, --max-time 1h (no space before the unit)","Check the flag actually received the value (quote it: --max-time \"10m\") and the unit is a recognized multiplier","Ensure the value is > 0; zero and negatives are rejected"],"exampleFix":"// before\nomp <cmd> --max-time 5min\n// after\nomp <cmd> --max-time 5m","handlingStrategy":"validation","validationCode":"const MAX_TIME_RE = /^(\\d+(?:\\.\\d+)?)([smh])?$/;\nconst MULT = { s: 1, m: 60, h: 3600 };\nfunction assertMaxTime(v) {\n  const m = MAX_TIME_RE.exec(String(v).trim());\n  const s = m ? Number(m[1]) * MULT[m[2] ?? 's'] : Number(v);\n  if (!Number.isFinite(s) || s <= 0) throw new Error(`Invalid --max-time: ${v}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  parse('--max-time', value);\n} catch (e) {\n  if (e instanceof CliUsageError && e.message.includes('--max-time')) {\n    console.error('Use seconds (30) or a duration like 5s / 10m / 1h, greater than zero.');\n  } else throw e;\n}","preventionTips":["Use plain seconds or the exact suffixes s/m/h with no space (`5s`, not `5 sec`)","Never pass 0 or negative values","Quote duration values in shell scripts so they arrive intact"],"tags":["cli","argument-validation","flag-parsing"],"backgroundTag":"invalid-flag-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}