{"record":{"id":"3db4d820882a1158","repo":"jackwener/OpenCLI","slug":"series-id-must-be-a-non-empty-value","errorCode":null,"errorMessage":"series_id must be a non-empty value","messagePattern":"series_id must be a non-empty value","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/autohome/utils.js","lineNumber":85,"sourceCode":"/** 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)`);\n    }\n    return m[1];\n}\n\nexport function clean(s) {\n    return String(s == null ? '' : s).replace(/\\s+/g, ' ').trim();\n}\n\nexport function requireLimit(value, def, max) {\n    const raw = value == null || value === '' ? def : value;\n    const n = typeof raw === 'number' ? raw : Number(String(raw).trim());\n    if (!Number.isInteger(n) || n < 1 || n > max) {\n        throw new ArgumentError(`limit must be an integer between 1 and ${max}`);\n    }\n    return n;","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/autohome/utils.js#L67-L103","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nseriesId(process.env.SERIES_ID) // undefined -> throws\n// after\nif (!process.env.SERIES_ID) throw new Error('Set SERIES_ID first');\nseriesId(process.env.SERIES_ID)","handlingStrategy":"validation","validationCode":"function isValidSeriesInput(v) {\n  const s = String(v ?? '').trim();\n  return s.length > 0;\n}\nif (!isValidSeriesInput(input)) throw new Error('Provide a non-empty series id');","typeGuard":"function hasSeriesInput(v) {\n  return typeof v === 'string' ? v.trim().length > 0 : v != null && String(v).trim().length > 0;\n}","tryCatchPattern":"try {\n  const id = seriesId(raw);\n} catch (err) {\n  if (err instanceof ArgumentError && /non-empty/.test(err.message)) {\n    console.error('Usage: seriesId <number-or-autohome-url>');\n  } else throw err;\n}","preventionTips":["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"],"tags":["validation","argument-error","input-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}