{"record":{"id":"a4ea26a8a26c02e1","repo":"jackwener/OpenCLI","slug":"label-did-not-include-a-stable-numeric-id","errorCode":null,"errorMessage":"${label} did not include a stable numeric id.","messagePattern":"(.+?) did not include a stable numeric id\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/autohome/utils.js","lineNumber":108,"sourceCode":"    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;\n}\n\nexport function requireStableId(value, label) {\n    const id = String(value ?? '').trim();\n    if (!/^\\d+$/.test(id)) throw new CommandExecutionError(`${label} did not include a stable numeric id.`);\n    return id;\n}\n\nexport function requireText(value, label) {\n    const text = clean(value);\n    if (!text) throw new CommandExecutionError(`${label} did not include a stable text value.`);\n    return text;\n}\n\nexport function assertPlainObject(value, label) {\n    if (!value || typeof value !== 'object' || Array.isArray(value)) {\n        throw new CommandExecutionError(`${label} returned an unexpected payload shape; expected an object.`);\n    }\n    return value;\n}\n\n/** Fetch an Autohome page as text. The grade + koubei pages are UTF-8. */\nexport async function ahFetch(url, contextHint) {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/autohome/utils.js#L90-L126","documentation":"requireStableId() throws CommandExecutionError when the value extracted from a fetched page (labeled by `label`) is not purely numeric digits. Autohome identifiers must be stable numeric ids; the library treats a missing/invalid one as an unexpected page payload rather than user error.","triggerScenarios":"A scraped page lacks the id (layout changed, region-specific page, anti-bot interstitial) so an empty or non-numeric string is passed; or the caller passes a name/slug instead of the numeric id.","commonSituations":"Autohome markup changes breaking extraction; logged-out or CAPTCHA pages returning fallback content; hardcoding a label where an id is expected.","solutions":["Verify the source page actually rendered the entity and inspect what `label` contained","Retry the fetch in case of an anti-bot/interstitial page","If you supply the value yourself, pass the numeric id, not a name or URL slug"],"exampleFix":"// before\nrequireStableId(result.name, 'series')\n// after\nrequireStableId(String(result.id), 'series')","handlingStrategy":"type-guard","validationCode":"if (!/^\\d+$/.test(String(value ?? '').trim())) {\n  throw new Error('Expected a numeric id for ' + label);\n}","typeGuard":"function isNumericId(v) {\n  return /^\\d+$/.test(String(v ?? '').trim());\n}","tryCatchPattern":"try {\n  const id = requireStableId(value, label);\n} catch (err) {\n  if (err instanceof CommandExecutionError && /stable numeric id/.test(err.message)) {\n    console.error(`Page did not yield a numeric id for ${label}; check the page or retry`);\n  } else throw err;\n}","preventionTips":["Verify pages render expected data (open the URL manually) before blaming your code","Retry fetches that hit anti-bot/interstitial pages","Pass ids, not names/slugs, into functions expecting stable ids"],"tags":["scraping","data-extraction","validation"],"backgroundTag":"missing-required-field","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}