{"record":{"id":"a3e709de927b01b6","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-max-lim-a3e709","errorCode":null,"errorMessage":"--limit must be an integer between 1 and ${MAX_LIMIT}","messagePattern":"--limit must be an integer between 1 and (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/linkedin-learning/shared.js","lineNumber":14,"sourceCode":"import { ArgumentError, AuthRequiredError } from '@jackwener/opencli/errors';\n\nexport const DOMAIN = 'www.linkedin.com';\nexport const MAX_LIMIT = 50;\n\nexport function normalizeWhitespace(value) {\n    return String(value ?? '').replace(/[  ]/g, ' ').replace(/\\s+/g, ' ').trim();\n}\n\nexport function parseLimit(value) {\n    if (value === undefined || value === null || value === '') return 10;\n    const limit = Number(value);\n    if (!Number.isInteger(limit) || limit < 1 || limit > MAX_LIMIT) {\n        throw new ArgumentError(`--limit must be an integer between 1 and ${MAX_LIMIT}`);\n    }\n    return limit;\n}\n\nexport function unwrapEvaluateResult(payload) {\n    if (payload && typeof payload === 'object' && 'data' in payload && 'session' in payload) return payload.data;\n    return payload;\n}\n\nexport function buildFetchScript(url, csrf) {\n    return String.raw`(async () => {\n    try {\n      const res = await fetch(${JSON.stringify(url)}, {\n        credentials: 'include',\n        headers: {\n          'csrf-token': ${JSON.stringify(csrf)},\n          'x-restli-protocol-version': '2.0.0',\n          accept: 'application/json',","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin-learning/shared.js#L1-L32","documentation":"An ArgumentError from the shared parseLimit helper: the --limit argument was supplied but is not an integer in the range 1..MAX_LIMIT (50). parseLimit returns a default of 10 when the value is undefined/null/empty, so this only fires on explicit but invalid input such as 0, -5, 'abc', 3.5, or 51.","triggerScenarios":"Passing --limit 0 or a negative number, a non-numeric string (--limit ten), a float (--limit 2.5, Number() yields NaN or a non-integer), or a value above MAX_LIMIT=50.","commonSituations":"Scripting the CLI with an unvalidated variable that is empty-but-not-null (e.g. string '0'), typos in shell scripts, users assuming the cap is unlimited, or passing float values from JSON config.","solutions":["Pass an integer between 1 and 50, or omit --limit to use the default of 10.","Coerce/validate the value in your wrapper script before invoking the CLI.","Use Math.trunc for floats and clamp to [1, 50].","Check the command help (args.help) for the documented range."],"exampleFix":"// before\nclio linkedin-learning search --keywords js --limit 100\n// after\nclio linkedin-learning search --keywords js --limit 50","handlingStrategy":"validation","validationCode":"function sanitizeLimit(v) {\n  if (v === undefined || v === null || v === '') return 10;\n  const n = Math.trunc(Number(v));\n  if (!Number.isFinite(n)) throw new Error(`--limit must be a number, got: ${v}`);\n  return Math.min(Math.max(n, 1), 50);\n}\n// usage: --limit $(sanitizeLimit \"$LIMIT\")","typeGuard":"function isValidLimit(v) {\n  if (v === undefined || v === null || v === '') return true;\n  const n = Number(v);\n  return Number.isInteger(n) && n >= 1 && n <= 50;\n}","tryCatchPattern":"try {\n  await run(['linkedin-learning', 'search', '--keywords', kw, '--limit', String(limit)]);\n} catch (e) {\n  if (e.message.startsWith('--limit must be')) {\n    limit = 10; // fall back to default and retry\n  } else throw e;\n}","preventionTips":["Validate/clamp user-supplied limits to 1..50 before invoking the CLI","Omit --limit entirely to get the default of 10","Truncate floats with Math.trunc before passing","Avoid passing shell variables that may be empty strings like '0' or blank"],"tags":["argument-validation","cli","input"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}