{"record":{"id":"2ceaaacc0beae58d","repo":"jackwener/OpenCLI","slug":"brand-must-be-a-non-empty-value","errorCode":null,"errorMessage":"brand must be a non-empty value","messagePattern":"brand must be a non-empty value","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/autohome/utils.js","lineNumber":70,"sourceCode":"    凯迪拉克: 'K', 克莱斯勒: 'K', 开瑞: 'K', 凯翼: 'K',\n    兰博基尼: 'L', 路虎: 'L', 雷克萨斯: 'L', 林肯: 'L', 铃木: 'L', 劳斯莱斯: 'L', 雷诺: 'L', 理想: 'L', 领克: 'L', 零跑: 'L', 路特斯: 'L', 岚图: 'L', 猎豹: 'L',\n    马自达: 'M', 迈巴赫: 'M', 名爵: 'M', 玛莎拉蒂: 'M', 迈凯伦: 'M',\n    哪吒: 'N',\n    欧拉: 'O',\n    奇瑞: 'Q', 起亚: 'Q',\n    日产: 'R', 荣威: 'R',\n    斯巴鲁: 'S', 斯柯达: 'S', 三菱: 'S', 上汽大通: 'S', 思皓: 'S', 赛力斯: 'S', smart: 'S',\n    特斯拉: 'T', 腾势: 'T', 坦克: 'T',\n    沃尔沃: 'W', 五菱: 'W', 蔚来: 'W', 威马: 'W', 魏牌: 'W', 问界: 'W',\n    现代: 'X', 雪佛兰: 'X', 雪铁龙: 'X', 小鹏: 'X', 星途: 'X', 小米: 'X',\n    英菲尼迪: 'Y', 一汽: 'Y', 野马: 'Y', 仰望: 'Y',\n    智己: 'Z', 中华: 'Z', 众泰: 'Z',\n};\n\n/** Resolve a brand name to its catalog initial letter. */\nexport function resolveBrandInitial(brandArg) {\n    const raw = String(brandArg || '').trim();\n    if (!raw) throw new ArgumentError('brand must be a non-empty value');\n    // single A-Z letter passes through (advanced: fetch a whole letter page)\n    if (/^[A-Za-z]$/.test(raw)) return raw.toUpperCase();\n    const key = raw.replace(/[·\\s]/g, '');\n    if (BRAND_INITIAL[key]) return BRAND_INITIAL[key];\n    if (BRAND_INITIAL[raw]) return BRAND_INITIAL[raw];\n    throw new ArgumentError(\n        'brand',\n        `unknown brand '${brandArg}'. Pass a known Chinese brand name (e.g. 宝马 / 比亚迪 / 理想) or a single A-Z catalog letter.`,\n    );\n}\n\n/** Normalize a series id: a bare number or an autohome URL containing it. */\nexport function normalizeSeriesId(rawInput) {\n    const raw = String(rawInput || '').trim();\n    if (!raw) throw new ArgumentError('series_id must be a non-empty value');\n    const m = raw.match(/\\/(?:s)?(\\d+)(?:\\/|$|\\.)/) || raw.match(/^s?(\\d+)$/);\n    if (!m) {\n        throw new ArgumentError(`'${rawInput}' does not look like an autohome series id (a number, or a k.autohome.com.cn/<id> URL)`);","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/autohome/utils.js#L52-L88","documentation":"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.","triggerScenarios":"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).","commonSituations":"Unset or misspelled environment variables in scripts; forgetting the argument entirely if the CLI doesn't enforce required options; piping empty config values.","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."],"exampleFix":"// before\nopencli autohome brand \"   \"\n// after\nopencli autohome brand \"宝马\"","handlingStrategy":"validation","validationCode":"const brand = (process.env.BRAND || '').trim();\nif (!brand) throw new Error('brand is required: pass a Chinese brand name or A-Z letter');","typeGuard":"function isNonEmptyBrand(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await run(['autohome', 'brand', brand]);\n} catch (e) {\n  if (/brand must be a non-empty value/.test(e.message)) {\n    console.error('BRAND variable is empty — set it, e.g. BRAND=宝马');\n  } else throw e;\n}","preventionTips":["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."],"tags":["validation","arguments","input"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}