{"record":{"id":"f81dfb1c8a34a93c","repo":"jackwener/OpenCLI","slug":"label-must-be-an-integer-between-min-and-m-f81dfb","errorCode":null,"errorMessage":"${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(raw)}","messagePattern":"(.+?) must be an integer between (.+?) and (.+?), got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/ask.js","lineNumber":34,"sourceCode":"    'answer',\n    'source_count',\n    'source_total_text',\n    'sources_summary',\n    'sources',\n    'warning',\n    'message_id',\n    'conversation_id',\n];\n\nfunction parseBoundedInteger(raw, defaultValue, min, max, label) {\n    const value = raw ?? defaultValue;\n    let parsed;\n    if (typeof value === 'number') {\n        parsed = value;\n    } else if (typeof value === 'string' && /^\\d+$/.test(value)) {\n        parsed = Number(value);\n    } else {\n        throw new ArgumentError(`${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(raw)}`);\n    }\n    if (!Number.isInteger(parsed) || parsed < min || parsed > max) {\n        throw new ArgumentError(`${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(raw)}`);\n    }\n    return parsed;\n}\n\nexport function parseAskTimeout(raw) {\n    return parseBoundedInteger(raw, 90, 1, 180, '--timeout');\n}\n\nexport function parseAskLimit(raw) {\n    return parseBoundedInteger(raw, 10, 1, 50, '--source-limit');\n}\n\nfunction cleanText(value) {\n    return String(value ?? '')\n        .replace(/<[^>]+>/g, '')","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/ask.js#L16-L52","documentation":"parseBoundedInteger validates the raw --timeout/--source-limit style option in the xiaohongshu ask command. It throws this ArgumentError when the value is neither a number nor a digit-only string — i.e. it cannot be interpreted as an integer at all. Note the message prints JSON.stringify(raw) while the type checks test `value` (raw with the default applied); a non-numeric, non-null raw always lands here.","triggerScenarios":"Passing --timeout or --source-limit values like 'abc', '1.5', '-5', '' (empty string), '90s', or true/false to the xiaohongshu ask command.","commonSituations":"Shell quoting issues passing '90s' or a duration with units; negative numbers (regex ^\\d+$ rejects the minus sign); decimal numbers; a config file supplying a boolean or object instead of a number/string.","solutions":["Pass a plain non-negative integer: --timeout 120, --source-limit 5","Remove units/suffixes ('90s' → '90') and any sign or decimals","Check the config file/env value feeding the option is a numeric string or number","Ensure the value is within 1–180 for --timeout and 1–50 for --source-limit (out-of-range hits the sibling throw at line 37)"],"exampleFix":"// before\nopencli xiaohongshu ask --timeout 90s \"query\"\n// after\nopencli xiaohongshu ask --timeout 90 \"query\"","handlingStrategy":"validation","validationCode":"function isValidIntOption(v, min, max) {\n  const n = typeof v === 'string' && /^\\d+$/.test(v) ? Number(v) : v;\n  return Number.isInteger(n) && n >= min && n <= max;\n}\nif (opts.timeout != null && !isValidIntOption(opts.timeout, 1, 180)) {\n  throw new Error('--timeout must be an integer 1-180');\n}","typeGuard":"function isBoundedInt(v, min, max) {\n  const n = typeof v === 'string' && /^\\d+$/.test(v) ? Number(v) : v;\n  return typeof n === 'number' && Number.isInteger(n) && n >= min && n <= max;\n}","tryCatchPattern":"try {\n  await xiaohongshuAsk({ query, timeout: opts.timeout });\n} catch (e) {\n  if (e.name === 'ArgumentError' && /must be an integer between/.test(e.message)) {\n    console.error('Bad flag value:', e.message, '— pass a plain integer, e.g. --timeout 120');\n  } else throw e;\n}","preventionTips":["Pass CLI flags as plain integers without units or signs","Reject non-numeric strings in wrapper scripts before invoking the CLI","Remember the regex only accepts digit strings — negatives and decimals always fail","Defaults are applied only for null/undefined, not for invalid values"],"tags":["argument-validation","cli-option","xiaohongshu"],"backgroundTag":"invalid-argument-type","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}