jackwener/OpenCLI · error · ArgumentError
limit must be an integer in [1, ${REDDIT_HOME_MAX_LIMIT}].
Error message
limit must be an integer in [1, ${REDDIT_HOME_MAX_LIMIT}]. What it means
ArgumentError thrown by parseRedditHomeLimit when the `limit` argument of `reddit home` is not an integer within [1, 100]. Empty/undefined/null values default to 25; anything else non-numeric, non-integer, <1, or >100 is rejected with the actual value echoed back.
Source
Thrown at clis/reddit/home.js:10
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
const REDDIT_HOME_MAX_LIMIT = 100;
export function parseRedditHomeLimit(raw) {
if (raw === undefined || raw === null || raw === '') return 25;
const n = Number(raw);
if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > REDDIT_HOME_MAX_LIMIT) {
throw new ArgumentError(
`limit must be an integer in [1, ${REDDIT_HOME_MAX_LIMIT}].`,
`Got: ${raw}`,
);
}
return n;
}
export function decodeRedditHtml(value) {
if (typeof value !== 'string' || !value) return '';
return value
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/gi, "'")
.replace(/'/g, "'");
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer between 1 and 100 inclusive, e.g. --limit 50.
- Omit the flag entirely to use the default of 25.
- Coerce/validate the value in your wrapper script before invoking the CLI.
- If you need more than 100 posts, paginate by re-running with different sort/time filters rather than raising limit.
Example fix
// before opencli reddit home --limit 250 // after opencli reddit home --limit 100
Defensive patterns
Strategy: validation
Validate before calling
function parseRedditHomeLimitSafe(raw) {
if (raw === undefined || raw === null || raw === '') return 25;
const n = Number(raw);
if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > 100) {
throw new RangeError(`limit must be an integer in [1, 100], got: ${raw}`);
}
return n;
}
// call before invoking the CLI
parseRedditHomeLimitSafe(process.env.LIMIT); Type guard
function isValidRedditHomeLimit(v) {
const n = Number(v);
return Number.isFinite(n) && Number.isInteger(n) && n >= 1 && n <= 100;
} Try / catch
try {
await opencli.reddit.home({ limit: userLimit });
} catch (e) {
if (/limit must be an integer/.test(e.message)) {
console.error('Please pass an integer 1-100; defaulting to 25.');
return opencli.reddit.home({ limit: 25 });
}
throw e;
} Prevention
- Clamp user input: Math.min(100, Math.max(1, Math.floor(n))).
- Omit the flag to accept the default of 25.
- Validate env/config values interpolated into CLI args before running.
- Remember the max is 100, matching Reddit's per-request listing cap.
When it happens
Trigger: Passing limit=0, a negative number, a float like 25.5, a non-numeric string like 'all' or '2e2' (Number('2e2')=200 -> out of range... actually 200>100), or any value above REDDIT_HOME_MAX_LIMIT=100.
Common situations: Users copying Reddit's web max (100) but off-by-one to 101; passing '25 ' with whitespace-plus-chars; scripts interpolating an unset variable producing 'undefined'; wanting 'all posts' and passing a huge limit.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- arxiv ${label} must be a positive integer
- brand must be a non-empty value
- Search keyword cannot be empty
- dblp ${label} must be a positive integer
- dblp ${label} cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ec8fa7a3f65d7b51.
Report an issue: GitHub.