{"record":{"id":"b8fdf12bf57aa8d8","repo":"jackwener/OpenCLI","slug":"xianyu-rank-must-be-a-positive-integer-from-xianyu","errorCode":null,"errorMessage":"xianyu rank must be a positive integer from xianyu inbox","messagePattern":"xianyu rank must be a positive integer from xianyu inbox","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/xianyu/im.js","lineNumber":25,"sourceCode":"\nexport function normalizeLimit(value, defaultValue = DEFAULT_INBOX_LIMIT, maxValue = MAX_INBOX_LIMIT, label = 'limit') {\n    const raw = String(value ?? '').trim();\n    if (!raw) return defaultValue;\n    if (!/^\\d+$/.test(raw)) {\n        throw new ArgumentError(`xianyu ${label} must be an integer between 1 and ${maxValue}`);\n    }\n    const n = Number(raw);\n    if (!Number.isSafeInteger(n) || n < 1 || n > maxValue) {\n        throw new ArgumentError(`xianyu ${label} must be an integer between 1 and ${maxValue}`);\n    }\n    return n;\n}\n\nexport function normalizeRank(value) {\n    const raw = String(value ?? '').trim();\n    if (!raw) return 0;\n    if (!/^\\d+$/.test(raw)) {\n        throw new ArgumentError('xianyu rank must be a positive integer from xianyu inbox');\n    }\n    const n = Number(raw);\n    if (!Number.isSafeInteger(n) || n < 1) {\n        throw new ArgumentError('xianyu rank must be a positive integer from xianyu inbox');\n    }\n    return n;\n}\n\nexport function requireText(value, label) {\n    const text = String(value ?? '').replace(/\\s+/g, ' ').trim();\n    if (!text) {\n        throw new ArgumentError(`${label} cannot be empty`);\n    }\n    return text;\n}\n\nexport function requireEvaluateObject(payload, label) {\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/im.js#L7-L43","documentation":"normalizeRank validates the 'rank' parameter, which selects a message by its position from xianyu inbox listings. It throws ArgumentError when the value is non-empty but not a pure digit string (e.g. 'abc', '1.5', '-3').","triggerScenarios":"Calling a xianyu command with rank='first', rank='1.5', rank='-1', or any non-numeric string; empty string returns 0 and is allowed.","commonSituations":"Passing a label or ordinal word instead of the numeric rank shown in inbox output; locale-formatted numbers ('1st'); parsing errors upstream.","solutions":["Pass a positive integer rank as shown in xianyu inbox output","Omit or pass empty to default to 0","Convert ordinals/labels to numbers before calling","Validate with /^\\d+$/ before invoking"],"exampleFix":"// before\nawait xianyuReply({ rank: 'first' }); // throws\n// after\nawait xianyuReply({ rank: '1' });","handlingStrategy":"validation","validationCode":"if (rank != null && rank !== '' && !/^\\d+$/.test(String(rank))) {\n  throw new Error('rank must be a positive integer');\n}","typeGuard":"function isValidRank(v) {\n  return v === '' || v == null || (/^\\d+$/.test(String(v)) && Number(v) >= 1);\n}","tryCatchPattern":"try {\n  await xianyuReply({ rank });\n} catch (e) {\n  if (e?.name === 'ArgumentError' && /rank/.test(e.message)) {\n    throw new Error(`bad rank '${rank}': use the numeric rank from xianyu inbox`);\n  }\n  throw e;\n}","preventionTips":["Use numeric ranks exactly as printed in inbox output","Convert ordinals ('first') to integers upstream","Validate with /^\\d+$/ before invoking"],"tags":["validation","argument-error","xianyu"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}