{"record":{"id":"47fcbd16358aac4a","repo":"jackwener/OpenCLI","slug":"label-did-not-include-a-stable-text-value","errorCode":null,"errorMessage":"${label} did not include a stable text value.","messagePattern":"(.+?) did not include a stable text value\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/autohome/utils.js","lineNumber":114,"sourceCode":"\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) {\n    let resp;\n    try {\n        resp = await fetch(url, {\n            headers: {\n                'User-Agent': UA,\n                Referer: `${AH_BASE}/`,","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/autohome/utils.js#L96-L132","documentation":"requireText() throws CommandExecutionError when the cleaned value for `label` is empty (null/undefined/whitespace). It guards that a required text field extracted from a page actually contains content.","triggerScenarios":"A scraped field missing on the page (e.g. no name/title rendered), passing null/'' from a failed lookup, or a whitespace-only value.","commonSituations":"Autohome page variants omitting a field; anti-bot or empty shell pages; upstream data absent for niche entities.","solutions":["Check whether the source page truly contains the field (open the URL manually)","Retry the fetch in case the page failed to render fully","Guard your own input with clean()/an emptiness check before calling"],"exampleFix":"// before\nrequireText(entry.title, 'name') // title undefined\n// after\nrequireText(entry.title ?? 'Unknown', 'name')","handlingStrategy":"type-guard","validationCode":"if (!String(value ?? '').trim()) {\n  throw new Error(label + ' is empty');\n}","typeGuard":"function hasText(v) {\n  return String(v ?? '').trim().length > 0;\n}","tryCatchPattern":"try {\n  const name = requireText(value, 'name');\n} catch (err) {\n  if (err instanceof CommandExecutionError && /stable text value/.test(err.message)) {\n    console.error('Field was empty on the page; supply a fallback or retry');\n  } else throw err;\n}","preventionTips":["Provide sensible fallbacks for optional scraped fields","Confirm the source page actually contains the field","Clean/trim values before validating"],"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"}