{"record":{"id":"b1e5257f932991a6","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-max-b1e525","errorCode":null,"errorMessage":"--limit must be an integer between 1 and ${max}","messagePattern":"--limit must be an integer between 1 and (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/shared.js","lineNumber":115,"sourceCode":"    throw new ArgumentError(`${label} must be an https LinkedIn URL without credentials or port`);\n  }\n  if (host !== 'linkedin.com' && host !== 'www.linkedin.com') {\n    throw new ArgumentError(`${label} must point to linkedin.com`);\n  }\n  return parsed.toString();\n}\n\nexport function requireStringArg(args, key, label = key) {\n  const value = normalizeWhitespace(args?.[key]);\n  if (!value) throw new ArgumentError(`${label} is required`);\n  return value;\n}\n\nexport function parseLimit(value, fallback, max) {\n  if (value === undefined || value === null || value === '') return fallback;\n  const parsed = Number(value);\n  if (!Number.isInteger(parsed) || parsed < 1 || parsed > max) {\n    throw new ArgumentError(`--limit must be an integer between 1 and ${max}`);\n  }\n  return parsed;\n}\n\nexport async function requireLinkedInCookie(page, context) {\n  let cookies;\n  try {\n    cookies = await page.getCookies({ url: 'https://www.linkedin.com' });\n  } catch (error) {\n    throw new CommandExecutionError(`LinkedIn cookie lookup failed: ${error?.message || error}`);\n  }\n  if (!Array.isArray(cookies)) {\n    throw new CommandExecutionError('LinkedIn cookie lookup returned malformed payload');\n  }\n  const jsession = cookies.find((c) => c.name === 'JSESSIONID')?.value;\n  if (!jsession) {\n    throw new AuthRequiredError(LINKEDIN_DOMAIN, `${context} requires an active signed-in LinkedIn browser session.`);\n  }","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/shared.js#L97-L133","documentation":"parseLimit converts the --limit argument to a number and throws ArgumentError unless it is an integer between 1 and the given max. Empty/undefined/null falls back to the provided default instead of throwing.","triggerScenarios":"Calling a command with e.g. `--limit 0`, `--limit -5`, `--limit 999` (above max), `--limit 3.5` (non-integer), or a non-numeric value like `--limit all`.","commonSituations":"Users confusing 0-based with 1-based limits, copying a limit from a tool with a higher max, shell scripts interpolating empty/invalid variables into the flag.","solutions":["Use an integer >= 1 and <= the max shown in the message (e.g. --limit 10).","Omit --limit entirely to use the built-in fallback default.","Fix non-numeric strings (e.g. 'all') with a plain number.","Clamp in scripts: `LIMIT=$(( LIMIT < 1 ? 1 : (LIMIT > MAX ? MAX : LIMIT) ))`."],"exampleFix":"// before\nnode cli.js list --limit 0\n// after\nnode cli.js list --limit 10   // integer between 1 and max, or omit for default","handlingStrategy":"validation","validationCode":"function assertLimit(v, max) {\n  if (v === undefined || v === null || v === '') return; // default applies\n  const n = Number(v);\n  if (!Number.isInteger(n) || n < 1 || n > max) {\n    throw new Error(`--limit must be an integer between 1 and ${max}`);\n  }\n}","typeGuard":"const isPositiveInt = (v) => Number.isInteger(v) && v >= 1;\nconst limitOk = (v, max) => v === undefined || v === null || v === '' ||\n  (isPositiveInt(Number(v)) && Number(v) <= max);","tryCatchPattern":"try {\n  await listCommand({ limit });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.startsWith('--limit')) {\n    const max = Number(e.message.match(/between 1 and (\\d+)/)?.[1] ?? 50);\n    console.error(`Invalid --limit; using default. Allowed: 1..${max}`);\n  } else throw e;\n}","preventionTips":["Omit --limit when you want the default instead of guessing values.","Remember limits are 1-based integers; 0 is invalid.","Clamp/round computed limits in scripts before passing them.","Read the max bound from the error message and respect it."],"tags":["argument-validation","cli-flags","range-validation","linkedin"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}