jackwener/OpenCLI · error · ArgumentError
flomo memos --${name} must be a positive integer
Error message
flomo memos --${name} must be a positive integer What it means
This error is thrown by parsePositiveIntArg in clis/flomo/memos.js:27 when a numeric CLI option (e.g. --limit) passed to `flomo memos` is not a plain positive integer string. The library validates raw command-line input before using it as an API query parameter, and ArgumentError is raised so the user gets a clear message instead of a malformed request. The template interpolates the option name, so the actual message names the offending flag.
Source
Thrown at clis/flomo/memos.js:27
const FLOMO_APP_DOMAIN = 'v.flomoapp.com';
const FLOMO_API_DOMAIN = 'flomoapp.com';
const MAX_LIMIT = 200;
function unwrapBrowserResult(value) {
if (value && typeof value === 'object' && 'session' in value && 'data' in value) {
return value.data;
}
return value;
}
function parsePositiveIntArg(value, name, fallback, max) {
if (value === undefined || value === null || value === '') {
return fallback;
}
const text = String(value).trim();
if (!/^\d+$/.test(text)) {
throw new ArgumentError(`flomo memos --${name} must be a positive integer`);
}
const parsed = Number(text);
if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > max) {
throw new ArgumentError(`flomo memos --${name} must be between 1 and ${max}`);
}
return parsed;
}
function parseSinceArg(value) {
if (value === undefined || value === null || value === '') {
return 0;
}
const text = String(value).trim();
if (!/^\d+$/.test(text)) {
throw new ArgumentError('flomo memos --since must be a non-negative Unix timestamp in seconds');
}
const parsed = Number(text);
if (!Number.isSafeInteger(parsed)) {View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a plain positive integer string, e.g. `flomo memos --limit 20`.
- Check the variable you interpolate is numeric-only: `echo "$LIMIT"` and remove units, commas, or symbols.
- Trim whitespace and validate with /^[0-9]+$/ in the calling script before invoking the CLI.
- Omit the flag entirely to use the built-in fallback value.
Example fix
// before flomo memos --limit "1,000" // after flomo memos --limit 1000
Defensive patterns
Strategy: validation
Validate before calling
function isValidPositiveInt(v) { return v === undefined || v === null || v === '' || /^\d+$/.test(String(v).trim()); }
if (!isValidPositiveInt(process.env.LIMIT)) { throw new Error('limit must be a positive integer'); } Type guard
function isPositiveIntString(v) { return typeof v === 'string' && /^\d+$/.test(v.trim()); } Try / catch
try {
await runMemos({ limit });
} catch (err) {
if (err.name === 'ArgumentError' && err.message.includes('must be a positive integer')) {
console.error(`Invalid --limit value "${limit}"; using default.`);
} else { throw err; }
} Prevention
- Quote and validate any shell variables before interpolating them into CLI flags.
- Never include units, commas, or signs in numeric CLI arguments.
- Validate with /^\d+$/ in wrapper scripts before invoking the CLI.
- Omit the flag rather than passing an empty/placeholder value.
When it happens
Trigger: Running `flomo memos --limit abc`, `--limit 10.5`, `--limit -3`, `--limit " 12x "`, `--limit ""` with surrounding invalid characters, or passing a value containing whitespace-plus-non-digits so the /^\d+$/ test fails. Empty/undefined/null values are allowed and fall back, so only present-but-non-numeric values trigger this.
Common situations: Shell variables containing stray characters or units (e.g. LIMIT=20x), copy-pasting values with hidden characters or commas (1,000), passing floats or negative numbers assuming the CLI accepts them, or scripting with unquoted/interpolated values that end up empty-with-spaces or non-numeric.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- ${name} must be${suffix} (got "${raw}")
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ed8b0405960a348a.
Report an issue: GitHub.