jackwener/OpenCLI · error · ArgumentError
account must be an integer between 0 and 20
Error message
account must be an integer between 0 and 20
What it means
parseAccount validates the Gmail account index, which selects the /mail/u/<index>/ profile in the browser. It must be an integer from 0 to 20 (defaulting to 0). Non-integers, negatives, or values above 20 throw ArgumentError.
Source
Thrown at clis/gmail/utils.js:43
}
export function parseLimit(raw, fallback = DEFAULT_LIMIT, max = MAX_LIMIT) {
const value = raw ?? fallback;
const limit = Number(value);
if (!Number.isInteger(limit) || limit <= 0) {
throw new ArgumentError('limit must be a positive integer');
}
if (limit > max) {
throw new ArgumentError(`limit must be <= ${max}`);
}
return limit;
}
export function parseAccount(raw) {
const value = raw ?? 0;
const account = Number(value);
if (!Number.isInteger(account) || account < 0 || account > 20) {
throw new ArgumentError('account must be an integer between 0 and 20');
}
return account;
}
function cleanString(value) {
return typeof value === 'string' ? value.trim() : '';
}
function gmailDate(value, label) {
let timestamp = Number(value);
if (!Number.isFinite(timestamp) || timestamp <= 0) {
throw new CommandExecutionError(`Gmail ${label} had an invalid timestamp`);
}
if (timestamp < 10_000_000_000) timestamp *= 1000;
if (timestamp > 10_000_000_000_000) timestamp /= 1000;
const date = new Date(timestamp);
if (Number.isNaN(date.getTime())) {
throw new CommandExecutionError(`Gmail ${label} had an invalid timestamp`);View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer account index between 0 and 20 (default 0 for the first signed-in account).
- Verify the correct index by checking the /mail/u/<index>/ URL in the browser when signed in.
- Omit --account to use the default (0).
- Fix the calling script so it doesn't pass NaN/undefined-derived values.
Example fix
// before cli --account 25 // after cli --account 1 // second signed-in Google account (/mail/u/1/)
Defensive patterns
Strategy: validation
Validate before calling
const n = Number(accountRaw ?? 0);
if (!Number.isInteger(n) || n < 0 || n > 20) {
throw new Error(`account must be an integer 0-20, got ${JSON.stringify(accountRaw)}`);
} Try / catch
try {
await gmailSearch({ account });
} catch (e) {
if (e instanceof ArgumentError && /account must be/.test(e.message)) {
return gmailSearch({ account: 0 }); // default account
}
throw e;
} Prevention
- Default to account 0 unless you know the /mail/u/<index>/ index you need.
- Confirm the index by checking the signed-in Gmail URL in the browser.
- Validate config/script inputs that supply the account index.
- Avoid hardcoding indexes above the supported 0-20 range.
When it happens
Trigger: Passing --account with a float, negative number, value > 20, or a non-numeric string; passing an account index that conceptually exists in Google but exceeds the library's guard range.
Common situations: Users with many Google accounts guessing an index above 20; scripts interpolating an unset variable producing NaN; typos like account: '1 ' with extra characters that fail Number parsing (spaces actually parse, but 'u1' does not).
Related errors
- limit must be a positive integer
- ${label} is required
- ${label} must be a positive integer
- ${label} must be <= ${maxValue}
- arxiv ${label} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/8a26abf58fda1fb7.
Report an issue: GitHub.