jackwener/OpenCLI · error · CliError
INVALID_ARGUMENT
INVALID_ARGUMENT
Error message
INVALID_ARGUMENT
What it means
The xiaoyuzhou podcast-episodes CLI validates the --limit argument before calling the API. If it is not a positive integer (e.g. 0, negative, or non-numeric like 'abc'), the CLI throws a CliError with code INVALID_ARGUMENT instead of sending a bad request upstream. It exists to fail fast with an actionable example in the hint.
Source
Thrown at clis/xiaoyuzhou/podcast-episodes.js:21
import { loadXiaoyuzhouCredentials, requestXiaoyuzhouJson } from './auth.js';
import { formatDuration, formatDate } from './utils.js';
cli({
site: 'xiaoyuzhou',
name: 'podcast-episodes',
access: 'read',
description: 'List episodes of a Xiaoyuzhou podcast',
domain: 'www.xiaoyuzhoufm.com',
strategy: Strategy.LOCAL,
browser: false,
args: [
{ name: 'id', positional: true, required: true, help: 'Podcast ID (from xiaoyuzhoufm.com URL)' },
{ name: 'limit', type: 'int', default: 20, help: 'Max episodes to show' },
],
columns: ['eid', 'title', 'duration', 'plays', 'date'],
func: async (args) => {
const requestedLimit = Number(args.limit);
if (!Number.isInteger(requestedLimit) || requestedLimit < 1) {
throw new CliError('INVALID_ARGUMENT', 'limit must be a positive integer', 'Example: --limit 5');
}
const credentials = loadXiaoyuzhouCredentials();
const response = await requestXiaoyuzhouJson('/v1/episode/list', {
method: 'POST',
body: { pid: args.id, order: 'desc', limit: requestedLimit },
credentials,
});
const episodes = response.data ?? [];
if (!Array.isArray(episodes)) {
throw new CliError('PARSE_ERROR', 'Unexpected API response format', 'Expected an array of episodes');
}
return episodes.map((ep) => ({
eid: ep.eid,
title: ep.title,
duration: formatDuration(ep.duration),
plays: ep.playCount,
date: formatDate(ep.pubDate),
}));View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive integer, e.g. `--limit 5`
- Check the value being passed in your script is a whole number >= 1
- If computing the limit dynamically, clamp it: Math.max(1, Math.floor(n))
- Omit --limit to use the default of 20
Example fix
// before opencli xiaoyuzhou podcast-episodes <pid> --limit 0 // after opencli xiaoyuzhou podcast-episodes <pid> --limit 20
Defensive patterns
Strategy: validation
Validate before calling
function isValidLimit(v){ const n = Number(v); return Number.isInteger(n) && n >= 1; }
if (!isValidLimit(opts.limit)) throw new Error('--limit must be a positive integer'); Type guard
const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) >= 1;
Try / catch
try { await run(['opencli','xiaoyuzhou','podcast-episodes',id,'--limit',limit]); } catch (e) { if (String(e).includes('INVALID_ARGUMENT')) { console.error('Fix --limit, must be positive integer'); process.exitCode = 2; } else throw e; } Prevention
- Validate numeric flags with Number.isInteger before passing them
- Clamp computed values: Math.max(1, Math.floor(n))
- Let the flag default (20) apply instead of passing values blindly
- Watch for shell stringification of numbers
When it happens
Trigger: Calling `opencli xiaoyuzhou podcast-episodes <id>` with `--limit 0`, a negative number, a non-integer float like `--limit 2.5`, or a non-numeric string such as `--limit ten`; the check `Number.isInteger(requestedLimit) && requestedLimit >= 1` fails.
Common situations: Copy-pasting flag values with stray whitespace or units ('20 eps'), scripting loops that compute limit as 0 for an empty batch, shell quoting issues producing empty strings, or confusing limit with an offset.
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
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bilibili unfollow target cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/24369540daca803f.
Report an issue: GitHub.