{"record":{"id":"4d814f72b8d5c849","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-in-1-notifi","errorCode":null,"errorMessage":"--limit must be a positive integer in [1, ${NOTIFICATIONS_LIMIT_MAX}], got ${JSON.stringify(raw)}","messagePattern":"--limit must be a positive integer in \\[1, (.+?)\\], got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/facebook/notifications.js","lineNumber":78,"sourceCode":"    '标记为已读，',\n    'Mark as read, ',\n    'Mark as Read, ',\n    'Marquer comme lu, ',\n    'Marcar como leído, ',\n    '既読にする, ',\n];\n\n// Localised \"unread\" badge labels that appear inside a `<div>` inside\n// the notification listitem. Used to set the typed `unread` boolean.\nexport const UNREAD_BADGE_LABELS = ['未读', 'Unread', 'No leído', '未読'];\n\nexport function normalizeNotificationsLimit(raw) {\n    if (raw === undefined || raw === null || raw === '') {\n        return NOTIFICATIONS_LIMIT_DEFAULT;\n    }\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > NOTIFICATIONS_LIMIT_MAX) {\n        throw new ArgumentError(\n            `--limit must be a positive integer in [1, ${NOTIFICATIONS_LIMIT_MAX}], got ${JSON.stringify(raw)}`,\n        );\n    }\n    return n;\n}\n\n// Pure: strip a Facebook locale-specific \"mark as read\" prefix from a\n// `<div role=\"button\">` aria-label so the caller gets the bare body\n// text. Returns the stripped body, or `null` when the input does not\n// start with a known prefix (i.e. we do not have a mark-as-read\n// aria-label and the caller should fall through to anchor text).\n//\n// `prefixes` is injected so the same function works in JSDOM tests\n// (passed the imported `MARK_AS_READ_PREFIXES`) and in the live IIFE\n// (the array is inlined into the embedded script via `JSON.stringify`).\nexport function stripMarkAsReadPrefix(label, prefixes) {\n    if (!label) return null;\n    const text = String(label).trim();","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/facebook/notifications.js#L60-L96","documentation":"ArgumentError from normalizeNotificationsLimit validating the --limit for facebook notifications. Unlike marketplace-listings, empty/undefined values fall back to a default, but any value that is not a finite integer in [1, NOTIFICATIONS_LIMIT_MAX] throws with the raw value JSON-stringified in the message for easy debugging.","triggerScenarios":"Passing `--limit abc` (NaN), `--limit 0`, `--limit -3`, `--limit 2.7`, a number above NOTIFICATIONS_LIMIT_MAX, or a non-numeric string via a script/variable.","commonSituations":"Shell variable expanding to a float or garbage; copy-pasting a max value exceeding the cap; programmatic callers passing unvalidated user input; mixing up limit semantics (page size vs count).","solutions":["Pass an integer between 1 and NOTIFICATIONS_LIMIT_MAX (check the constant in clis/facebook/notifications.js for the cap)","Omit --limit entirely to use NOTIFICATIONS_LIMIT_DEFAULT","Pre-validate: Number.isInteger(n) && n >= 1 && n <= NOTIFICATIONS_LIMIT_MAX","Inspect the JSON.stringify(raw) in the message to see exactly what was received"],"exampleFix":"// before\n--limit 999999\n// after\n--limit 50","handlingStrategy":"validation","validationCode":"function validateNotificationsLimit(raw, max) {\n  if (raw === undefined || raw === null || raw === '') return; // default applies\n  const n = typeof raw === 'number' ? raw : Number(raw);\n  if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > max) {\n    throw new Error(`--limit must be a positive integer in [1, ${max}], got ${JSON.stringify(raw)}`);\n  }\n}","typeGuard":"const isValidLimit = (v, max) => { const n = Number(v); return Number.isInteger(n) && n >= 1 && n <= max; };","tryCatchPattern":"try {\n  await getFacebookNotifications(page, { limit });\n} catch (e) {\n  if (/--limit must be a positive integer/.test(e.message)) {\n    limit = DEFAULT; // retry with default\n  } else throw e;\n}","preventionTips":["Coerce and clamp user-supplied limits before calling","Omit --limit to get the default","Check NOTIFICATIONS_LIMIT_MAX for the allowed ceiling","Read the JSON.stringify(raw) in the message to see the bad input"],"tags":["argument-validation","cli-input"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}