{"record":{"id":"ce7f9fe64459e540","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-100-got-ce7f9f","errorCode":null,"errorMessage":"--limit must be an integer between 1 and 100, got ${JSON.stringify(raw)}","messagePattern":"--limit must be an integer between 1 and 100, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/smzdm/search.js","lineNumber":41,"sourceCode":"    return rows;\n}\n\nfunction 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 = [];","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/smzdm/search.js#L23-L59","documentation":"parseLimit converts the raw --limit CLI argument to a number and requires it to be a finite integer. If the raw value is missing, non-numeric, or a float (e.g. \"abc\", \"\", 2.5), an ArgumentError is thrown with the JSON-encoded offending value so the caller can see exactly what was passed.","triggerScenarios":"Calling the smzdm search command with --limit set to a non-integer or non-numeric value: --limit abc, --limit \"\", --limit 2.5, or --limit with no value yielding undefined/null.","commonSituations":"Typo in the flag value; shell quoting issues passing an empty string; scripts interpolating an unbound variable into --limit; users assuming a float or 'all' is accepted.","solutions":["Pass a whole number between 1 and 100: --limit 20.","Check for empty or unset values in shell scripts calling the CLI (use ${VAR:-20} defaults).","Validate/round the value in wrapper scripts before invoking the CLI."],"exampleFix":"// before\nopencli smzdm search headphones --limit 2.5\n// after\nopencli smzdm search headphones --limit 25","handlingStrategy":"validation","validationCode":"const n = Number(raw);\nif (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > 100) throw new Error(`limit must be an integer 1-100, got ${JSON.stringify(raw)}`);","typeGuard":null,"tryCatchPattern":"try {\n  await run(['smzdm', 'search', q, '--limit', String(limit)]);\n} catch (e) {\n  if (e.message.includes('--limit must be an integer')) { console.error(`Fix --limit value: ${e.message}`); }\n  else throw e;\n}","preventionTips":["Default to a known-good value like --limit 20 in scripts.","Use ${VAR:-20} shell defaults so unset vars never reach the flag.","Round/parseInt user input before passing it as --limit."],"tags":["cli","argument-validation","input-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}