jackwener/OpenCLI · error · ArgumentError
series_id must be a non-empty value
Error message
series_id must be a non-empty value
What it means
normalizeSeriesId() throws this ArgumentError when its input is empty after string conversion and trimming. The library requires a non-empty series id (a bare number or an autohome series URL) to build request URLs. It is an upfront input validation guard.
Source
Thrown at clis/autohome/utils.js:85
/** Resolve a brand name to its catalog initial letter. */
export function resolveBrandInitial(brandArg) {
const raw = String(brandArg || '').trim();
if (!raw) throw new ArgumentError('brand must be a non-empty value');
// single A-Z letter passes through (advanced: fetch a whole letter page)
if (/^[A-Za-z]$/.test(raw)) return raw.toUpperCase();
const key = raw.replace(/[·\s]/g, '');
if (BRAND_INITIAL[key]) return BRAND_INITIAL[key];
if (BRAND_INITIAL[raw]) return BRAND_INITIAL[raw];
throw new ArgumentError(
'brand',
`unknown brand '${brandArg}'. Pass a known Chinese brand name (e.g. 宝马 / 比亚迪 / 理想) or a single A-Z catalog letter.`,
);
}
/** Normalize a series id: a bare number or an autohome URL containing it. */
export function normalizeSeriesId(rawInput) {
const raw = String(rawInput || '').trim();
if (!raw) throw new ArgumentError('series_id must be a non-empty value');
const m = raw.match(/\/(?:s)?(\d+)(?:\/|$|\.)/) || raw.match(/^s?(\d+)$/);
if (!m) {
throw new ArgumentError(`'${rawInput}' does not look like an autohome series id (a number, or a k.autohome.com.cn/<id> URL)`);
}
return m[1];
}
export function clean(s) {
return String(s == null ? '' : s).replace(/\s+/g, ' ').trim();
}
export function requireLimit(value, def, max) {
const raw = value == null || value === '' ? def : value;
const n = typeof raw === 'number' ? raw : Number(String(raw).trim());
if (!Number.isInteger(n) || n < 1 || n > max) {
throw new ArgumentError(`limit must be an integer between 1 and ${max}`);
}
return n;View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty series id: a bare number like '585' or a k.autohome.com.cn/<id> URL
- Check where the argument comes from (CLI arg, env var, config) and ensure it is actually populated
- Add your own emptiness check before calling to fail with a clearer message
Example fix
// before
seriesId(process.env.SERIES_ID) // undefined -> throws
// after
if (!process.env.SERIES_ID) throw new Error('Set SERIES_ID first');
seriesId(process.env.SERIES_ID) Defensive patterns
Strategy: validation
Validate before calling
function isValidSeriesInput(v) {
const s = String(v ?? '').trim();
return s.length > 0;
}
if (!isValidSeriesInput(input)) throw new Error('Provide a non-empty series id'); Type guard
function hasSeriesInput(v) {
return typeof v === 'string' ? v.trim().length > 0 : v != null && String(v).trim().length > 0;
} Try / catch
try {
const id = seriesId(raw);
} catch (err) {
if (err instanceof ArgumentError && /non-empty/.test(err.message)) {
console.error('Usage: seriesId <number-or-autohome-url>');
} else throw err;
} Prevention
- Always pass a literal series id or URL, never an unguarded env/config value
- Default missing inputs at the CLI entrypoint before calling library functions
- Trim inputs early in your own pipeline
When it happens
Trigger: Calling seriesId/normalizeSeriesId with undefined, null, '', 0, or a whitespace-only string, e.g. seriesId('') or a CLI invocation where the series_id argument was omitted.
Common situations: Forgetting a required CLI flag or positional argument; a config/env variable that resolves to empty; a variable that is unexpectedly undefined because an upstream lookup failed.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Invalid Chess.com username "${value}" Usernames are 3-25 cha
- coingecko derivatives limit must be a positive integer
- limit must be a positive integer
- Search keyword cannot be empty
- ${label} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/3db4d820882a1158.
Report an issue: GitHub.