{"record":{"id":"776e3928bbb830f1","repo":"jackwener/OpenCLI","slug":"facebook-search-limit-must-be-an-integer-between","errorCode":null,"errorMessage":"facebook search --limit must be an integer between 1 and ${MAX_LIMIT}","messagePattern":"facebook search --limit must be an integer between 1 and (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/facebook/search.js","lineNumber":10,"sourceCode":"import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\n\nconst FACEBOOK_HOME = 'https://www.facebook.com';\nconst MAX_LIMIT = 50;\n\nfunction requireLimit(value) {\n  const n = Number(value);\n  if (!Number.isInteger(n) || n < 1 || n > MAX_LIMIT) {\n    throw new ArgumentError(`facebook search --limit must be an integer between 1 and ${MAX_LIMIT}`);\n  }\n  return n;\n}\n\nfunction requireQuery(value) {\n  const q = String(value ?? '').trim();\n  if (!q) throw new ArgumentError('facebook search requires a non-empty query');\n  return q;\n}\n\nfunction unwrapBrowserResult(value) {\n  if (value && typeof value === 'object' && 'data' in value) return value.data;\n  return value;\n}\n\n// Modern facebook.com /search/top renders results inside [role=\"feed\"] as\n// entity/content links (people, pages, groups, posts) — [role=\"article\"] /\n// [role=\"listitem\"] no longer wrap them — and FB seeds scrambled hidden-char","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/facebook/search.js#L1-L28","documentation":"ArgumentError thrown by requireLimit in clis/facebook/search.js when the --limit value is not an integer in the 1–MAX_LIMIT (50) range. The function coerces input with Number() and rejects NaN, non-integers, and out-of-range values before any network call. This is an input validation guard, so the error fires immediately and locally.","triggerScenarios":"Calling facebook search with --limit 0, --limit 51, --limit abc, --limit 2.5, or an empty value that Number() coerces to NaN.","commonSituations":"Passing a string from CLI args without parsing; copy-pasting a limit above the 50 cap; scripting with a computed value that is a float or null; forgetting the flag so undefined becomes NaN.","solutions":["Pass an integer between 1 and 50, e.g. --limit 20","Validate/coerce the value with Number(value) and Number.isInteger before calling","Clamp computed values: Math.min(50, Math.max(1, Math.round(n)))"],"exampleFix":"// before\ncli.search({ limit: '100' });\n// after\nconst n = Math.min(50, Math.max(1, Math.round(Number(rawLimit))));\ncli.search({ limit: n });","handlingStrategy":"validation","validationCode":"function validLimit(v) {\n  const n = Number(v);\n  return Number.isInteger(n) && n >= 1 && n <= 50 ? n : null;\n}\nconst limit = validLimit(rawLimit);\nif (limit === null) throw new Error('--limit must be an integer between 1 and 50');","typeGuard":"function isAllowedLimit(v) {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 50;\n}","tryCatchPattern":"try {\n  await cli.search({ query, limit });\n} catch (err) {\n  if (/must be an integer between 1 and/.test(err.message)) {\n    console.error('Please pass --limit as an integer 1-50');\n    process.exitCode = 2;\n    return;\n  }\n  throw err;\n}","preventionTips":["Always coerce and validate CLI args before calling search","Clamp computed limits to [1, 50] with Math.min/Math.max","Document the 50-result cap in your wrapper scripts"],"tags":["validation","argument-error","cli-input"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}