jackwener/OpenCLI · error · ArgumentError
brand must be a non-empty value
Error message
brand must be a non-empty value
What it means
ArgumentError thrown by resolveBrandInitial when the brand argument is empty after trimming (String(brandArg || '').trim() === ''). The library needs either a Chinese brand name or a single A-Z letter to resolve a catalog initial, so an empty value is rejected up front.
Source
Thrown at clis/autohome/utils.js:70
凯迪拉克: 'K', 克莱斯勒: 'K', 开瑞: 'K', 凯翼: 'K',
兰博基尼: 'L', 路虎: 'L', 雷克萨斯: 'L', 林肯: 'L', 铃木: 'L', 劳斯莱斯: 'L', 雷诺: 'L', 理想: 'L', 领克: 'L', 零跑: 'L', 路特斯: 'L', 岚图: 'L', 猎豹: 'L',
马自达: 'M', 迈巴赫: 'M', 名爵: 'M', 玛莎拉蒂: 'M', 迈凯伦: 'M',
哪吒: 'N',
欧拉: 'O',
奇瑞: 'Q', 起亚: 'Q',
日产: 'R', 荣威: 'R',
斯巴鲁: 'S', 斯柯达: 'S', 三菱: 'S', 上汽大通: 'S', 思皓: 'S', 赛力斯: 'S', smart: 'S',
特斯拉: 'T', 腾势: 'T', 坦克: 'T',
沃尔沃: 'W', 五菱: 'W', 蔚来: 'W', 威马: 'W', 魏牌: 'W', 问界: 'W',
现代: 'X', 雪佛兰: 'X', 雪铁龙: 'X', 小鹏: 'X', 星途: 'X', 小米: 'X',
英菲尼迪: 'Y', 一汽: 'Y', 野马: 'Y', 仰望: 'Y',
智己: 'Z', 中华: 'Z', 众泰: 'Z',
};
/** 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)`);View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty brand value, e.g. 宝马 or a catalog letter like B.
- In scripts, guard ${BRAND:?not set} or check for emptiness before invoking.
- Quote arguments so spaces don't collapse them into nothing.
Example fix
// before opencli autohome brand " " // after opencli autohome brand "宝马"
Defensive patterns
Strategy: validation
Validate before calling
const brand = (process.env.BRAND || '').trim();
if (!brand) throw new Error('brand is required: pass a Chinese brand name or A-Z letter'); Type guard
function isNonEmptyBrand(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await run(['autohome', 'brand', brand]);
} catch (e) {
if (/brand must be a non-empty value/.test(e.message)) {
console.error('BRAND variable is empty — set it, e.g. BRAND=宝马');
} else throw e;
} Prevention
- Check required shell variables with ${BRAND:?unset} before invoking.
- Trim and validate inputs in wrapper scripts before passing them on.
- Make required options explicit in your own CLI wrappers.
When it happens
Trigger: Calling a command that requires a brand with an empty string, whitespace-only value, null/undefined, or an unset shell variable (e.g. brand="$BRAND" with BRAND empty).
Common situations: Unset or misspelled environment variables in scripts; forgetting the argument entirely if the CLI doesn't enforce required options; piping empty config values.
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
- arxiv ${label} must be a positive integer
- Search keyword cannot be empty
- dblp ${label} must be a positive integer
- dblp ${label} cannot be empty
- dblp paper key is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/2ceaaacc0beae58d.
Report an issue: GitHub.