{"record":{"id":"7429f352e2d920fc","repo":"jackwener/OpenCLI","slug":"limit-must-be-between-1-and-100-got-parsed-7429f3","errorCode":null,"errorMessage":"--limit must be between 1 and 100, got ${parsed}","messagePattern":"--limit must be between 1 and 100, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/smzdm/search.js","lineNumber":44,"sourceCode":"function parseLimit(raw) {\n    let parsed;\n    if (raw == null) {\n        parsed = 20;\n    }\n    else if (typeof raw === 'number') {\n        parsed = raw;\n    }\n    else if (typeof raw === 'string' && /^[0-9]+$/.test(raw)) {\n        parsed = Number(raw);\n    }\n    else {\n        parsed = NaN;\n    }\n    if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {\n        throw new ArgumentError(`--limit must be an integer between 1 and 100, got ${JSON.stringify(raw)}`);\n    }\n    if (parsed < 1 || parsed > 100) {\n        throw new ArgumentError(`--limit must be between 1 and 100, got ${parsed}`);\n    }\n    return parsed;\n}\n\n/**\n * Build the in-page extraction script. Every result row carries the full\n * declared column set; interaction metrics default to 0 and the update time\n * to '' when a list item omits them, so no column is ever silently dropped.\n */\nfunction buildSmzdmSearchJs(limit) {\n    return `\n      (() => {\n        const limit = ${limit};\n        const items = document.querySelectorAll('li.feed-row-wide');\n        const results = [];\n        const normalizeCount = (text) => {\n          const raw = (text || '').replace(/,/g, '').trim();\n          const match = raw.match(/(\\\\d+(?:\\\\.\\\\d+)?)\\\\s*([万kK]?)/);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/smzdm/search.js#L26-L62","documentation":"After parseLimit confirms the --limit value is a finite integer, it enforces the supported range of 1–100. Integers outside that range throw this ArgumentError including the parsed value. The range cap typically mirrors the upstream site/page-size limit.","triggerScenarios":"Passing --limit 0, --limit -5, or --limit 101+ to the smzdm search command with a value that is a valid integer but out of bounds.","commonSituations":"Users wanting 'everything' guess a huge limit like 1000; computed limits from page math produce 0; copy-pasted configs use 500.","solutions":["Use a limit between 1 and 100: --limit 100 is the maximum.","If more results are needed, paginate with multiple searches instead of one large limit.","Clamp the value in wrapper scripts: Math.min(100, Math.max(1, n))."],"exampleFix":"// before\nopencli smzdm search headphones --limit 500\n// after\nopencli smzdm search headphones --limit 100","handlingStrategy":"validation","validationCode":"const clamped = Math.min(100, Math.max(1, Math.round(Number(raw))));\nif (!Number.isInteger(clamped)) throw new Error('limit must resolve to an integer');","typeGuard":null,"tryCatchPattern":"try {\n  await run(['smzdm', 'search', q, '--limit', String(limit)]);\n} catch (e) {\n  if (e.message.includes('--limit must be between 1 and 100')) { limit = 100; /* retry clamped */ }\n  else throw e;\n}","preventionTips":["Clamp limits at the call site with Math.min/Math.max before invoking.","Remember 100 is the maximum; paginate for more results.","Guard computed limits against 0/negative results from page math."],"tags":["cli","argument-validation","range-check"],"backgroundTag":"argument-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}