{"record":{"id":"249b613f3a308caf","repo":"jackwener/OpenCLI","slug":"label-did-not-include-a-stable-numeric-id-249b61","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/guazi/utils.js","lineNumber":101,"sourceCode":"    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 clean(s) {\n    return String(s == null ? '' : s).replace(/\\s+/g, ' ').trim();\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 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\n/** Fetch a Guazi mobile page as HTML text, throwing typed errors. */\nexport async function guaziFetch(path, contextHint) {\n    let resp;\n    try {\n        resp = await fetch(`${GUAZI_M_BASE}${path}`, {\n            headers: {\n                'User-Agent': UA,\n                Referer: `${GUAZI_M_BASE}/`,\n                'Accept-Language': 'zh-CN,zh;q=0.9',\n            },\n        });\n    } catch (err) {\n        throw new CommandExecutionError(`guazi ${contextHint} network error: ${err?.message || err}`);\n    }\n    if (!resp.ok) {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/guazi/utils.js#L83-L119","documentation":"requireStableId validates that a value is a string of only digits, used to guarantee stable numeric IDs (e.g. car IDs scraped from Guazi pages). It throws CommandExecutionError when the value is missing, empty, or contains any non-digit characters after trimming.","triggerScenarios":"Calling requireStableId(null), requireStableId(''), requireStableId('  '), requireStableId('abc123'), requireStableId('c123456'), or any value whose String() form is not fully matched by /^\\d+$/. Called from clueId when a user-supplied or scraped clue lacks a numeric id.","commonSituations":"Passing a full car-detail slug like 'c654321' or a URL instead of the bare numeric id; pasting an id with spaces, letters, or a trailing newline; a field that is undefined because an upstream scrape failed or the CLI flag was omitted.","solutions":["Extract the bare numeric id before calling, e.g. value.match(/c(\\d+)/)?.[1] or strip non-digits","Ensure the CLI argument/flag supplying the id is actually present and populated","Trim and coerce with String(value).trim() yourself and confirm the result matches /^\\d+$/","If the source data has no numeric id, use requireStableText (the sibling helper) instead"],"exampleFix":"// before\nconst id = requireStableId('c654321', 'car id');\n// throws: car id did not include a stable numeric id.\n\n// after\nconst id = requireStableId('c654321'.replace(/^c/i, ''), 'car id');\n// => '654321'","handlingStrategy":"validation","validationCode":"function isStableId(v){ return typeof String(v ?? '').trim() === 'string' && /^\\d+$/.test(String(v ?? '').trim()); }\nif (!isStableId(raw)) throw new Error('id must be numeric');\nrequireStableId(raw, 'car id');","typeGuard":"const isNumericId = (v) => /^\\d+$/.test(String(v ?? '').trim());","tryCatchPattern":"try {\n  const id = requireStableId(value, 'car id');\n} catch (e) {\n  if (e instanceof CommandExecutionError && /stable numeric id/.test(e.message)) {\n    // prompt user / re-derive id from slug\n  } else throw e;\n}","preventionTips":["Extract numeric ids from slugs/URLs with a regex like /c(\\d+)/ before validation","Always trim user input before passing to requireStableId","Distinguish text clues (use requireStableText) from numeric ids (requireStableId) up front","Validate CLI flags early and fail with a usage message"],"tags":["validation","input","cli"],"backgroundTag":"schema-validation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}