{"record":{"id":"dbd748e22e948b45","repo":"jackwener/OpenCLI","slug":"weixin-search-name-must-be-a-positive-integer","errorCode":null,"errorMessage":"weixin search --${name} must be a positive integer","messagePattern":"weixin search --(.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weixin/search.js","lineNumber":14,"sourceCode":"import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\n\nconst SOGOU_WEIXIN_DOMAIN = 'weixin.sogou.com';\nconst DEFAULT_PAGE = 1;\nconst DEFAULT_LIMIT = 10;\nconst MAX_LIMIT = 10;\n\nfunction normalizePositiveInteger(value, name, defaultValue, maxValue) {\n    if (value === undefined || value === null)\n        return defaultValue;\n    const text = String(value).trim();\n    if (!/^\\d+$/.test(text)) {\n        throw new ArgumentError(`weixin search --${name} must be a positive integer`, `Pass --${name} as a whole number${maxValue ? ` from 1 to ${maxValue}` : ' greater than 0'}.`);\n    }\n    const parsed = Number(text);\n    if (!Number.isSafeInteger(parsed) || parsed < 1 || (maxValue && parsed > maxValue)) {\n        throw new ArgumentError(`weixin search --${name} is out of range`, `Pass --${name} as a whole number${maxValue ? ` from 1 to ${maxValue}` : ' greater than 0'}.`);\n    }\n    return parsed;\n}\n\nfunction normalizePage(page) {\n    return normalizePositiveInteger(page, 'page', DEFAULT_PAGE);\n}\n\nfunction normalizeLimit(limit) {\n    return normalizePositiveInteger(limit, 'limit', DEFAULT_LIMIT, MAX_LIMIT);\n}\n\nfunction buildSearchUrl(query, pageNo) {\n    const searchUrl = new URL('https://weixin.sogou.com/weixin');","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weixin/search.js#L1-L32","documentation":"`normalizePositiveInteger` in the weixin search command validates --page and --limit inputs. If the value is not undefined/null and fails the /^\\d+$/ whole-number test (empty string, non-numeric text, decimals like '1.5', or negatives like '-1'), it throws ArgumentError with message 'weixin search --<name> must be a positive integer'. ArgumentError carries code ARGUMENT and Unix exit code 2 (usage error).","triggerScenarios":"Calling `opencli weixin search` with --page or --limit set to a non-integer string, e.g. `--page abc`, `--limit 1.5`, `--page -3`, `--limit ''`, or a value with whitespace/symbols like '1,000'.","commonSituations":"Scripts passing unquoted or malformed variables into the CLI flags; users copying '1,000' or '10 times' into --limit; locale-formatted numbers; a wrapper passing empty string when a value is unset.","solutions":["Pass --page and --limit as plain positive integers, e.g. --page 1 --limit 10","Remove thousands separators, signs, and decimals from the value before invoking the CLI","In scripts, validate/coerce the value to an integer string before calling the command"],"exampleFix":"// before\nopencli weixin search \"golang\" --limit 1,000   // ArgumentError\n// after\nopencli weixin search \"golang\" --limit 1000","handlingStrategy":"validation","validationCode":"function isValidPositiveInt(v) {\n  if (v === undefined || v === null) return true; // defaults apply\n  return /^\\d+$/.test(String(v).trim());\n}\nif (!isValidPositiveInt(page)) throw new Error('--page must be a positive integer');\nif (!isValidPositiveInt(limit)) throw new Error('--limit must be a positive integer');","typeGuard":"function isPositiveIntString(v) {\n  return typeof v === 'string' || typeof v === 'number'\n    ? /^\\d+$/.test(String(v).trim())\n    : false;\n}","tryCatchPattern":"try {\n  await run(['weixin', 'search', q, '--page', String(page), '--limit', String(limit)]);\n} catch (e) {\n  if (e instanceof CliError && e.code === 'ARGUMENT') {\n    console.error(`Bad flag value: ${e.message} (${e.hint})`); process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Always build CLI flags with String(Math.trunc(v)) for computed values","Never pass locale-formatted numbers ('1,000') or empty strings into --page/--limit","Validate inputs at the script boundary before shelling out to the CLI","Remember ArgumentError means exit code 2 (usage), so fix the invocation, not the environment"],"tags":["argument-validation","cli-usage","weixin"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}