jackwener/OpenCLI · error · ArgumentError
--limit must be a positive integer in [1, ${NOTIFICATIONS_LI
Error message
--limit must be a positive integer in [1, ${NOTIFICATIONS_LIMIT_MAX}], got ${JSON.stringify(raw)} What it means
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.
Source
Thrown at clis/facebook/notifications.js:78
'标记为已读,',
'Mark as read, ',
'Mark as Read, ',
'Marquer comme lu, ',
'Marcar como leído, ',
'既読にする, ',
];
// Localised "unread" badge labels that appear inside a `<div>` inside
// the notification listitem. Used to set the typed `unread` boolean.
export const UNREAD_BADGE_LABELS = ['未读', 'Unread', 'No leído', '未読'];
export function normalizeNotificationsLimit(raw) {
if (raw === undefined || raw === null || raw === '') {
return NOTIFICATIONS_LIMIT_DEFAULT;
}
const n = typeof raw === 'number' ? raw : Number(raw);
if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > NOTIFICATIONS_LIMIT_MAX) {
throw new ArgumentError(
`--limit must be a positive integer in [1, ${NOTIFICATIONS_LIMIT_MAX}], got ${JSON.stringify(raw)}`,
);
}
return n;
}
// Pure: strip a Facebook locale-specific "mark as read" prefix from a
// `<div role="button">` aria-label so the caller gets the bare body
// text. Returns the stripped body, or `null` when the input does not
// start with a known prefix (i.e. we do not have a mark-as-read
// aria-label and the caller should fall through to anchor text).
//
// `prefixes` is injected so the same function works in JSDOM tests
// (passed the imported `MARK_AS_READ_PREFIXES`) and in the live IIFE
// (the array is inlined into the embedded script via `JSON.stringify`).
export function stripMarkAsReadPrefix(label, prefixes) {
if (!label) return null;
const text = String(label).trim();View on GitHub (pinned to 49907e53dc)
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
Example fix
// before --limit 999999 // after --limit 50
Defensive patterns
Strategy: validation
Validate before calling
function validateNotificationsLimit(raw, max) {
if (raw === undefined || raw === null || raw === '') return; // default applies
const n = typeof raw === 'number' ? raw : Number(raw);
if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > max) {
throw new Error(`--limit must be a positive integer in [1, ${max}], got ${JSON.stringify(raw)}`);
}
} Type guard
const isValidLimit = (v, max) => { const n = Number(v); return Number.isInteger(n) && n >= 1 && n <= max; }; Try / catch
try {
await getFacebookNotifications(page, { limit });
} catch (e) {
if (/--limit must be a positive integer/.test(e.message)) {
limit = DEFAULT; // retry with default
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- archive snapshots url cannot be empty
- archive snapshots limit must be a positive integer
- archive snapshots limit must be <= 1000
- archive snapshots ${key} must be a digit-only timestamp (YYY
- bilibili unfollow target must be a valid space.bilibili.com/
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4d814f72b8d5c849.
Report an issue: GitHub.