{"record":{"id":"3b3769535c8fc5b7","repo":"jackwener/OpenCLI","slug":"label-must-be-a-numeric-id-3b3769","errorCode":null,"errorMessage":"${label} must be a numeric ID","messagePattern":"(.+?) must be a numeric ID","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/utils.js","lineNumber":5,"sourceCode":"import { ArgumentError } from '@jackwener/opencli/errors';\nexport function normalizeNumericId(value, label, example) {\n    const normalized = String(value || '').trim();\n    if (!/^\\d+$/.test(normalized)) {\n        throw new ArgumentError(`${label} must be a numeric ID`, `Pass a numeric ${label}, for example: ${example}`);\n    }\n    return normalized;\n}\n","sourceCodeStart":1,"sourceCodeEnd":9,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/utils.js#L1-L9","documentation":"normalizeNumericId validates that an ID argument (for sku, itemId, userId commands) is a string of digits only. Anything else — including numbers with signs, decimals, whitespace-plus-symbols, or alphanumeric IDs — raises an ArgumentError instructing the caller to pass a numeric ID with an example.","triggerScenarios":"Calling `xianyu sku` / `xianyu item` / `xianyu user` with a non-numeric ID such as 'abc123', '1.5', '-42', a full item URL pasted instead of the ID, or an empty/null value.","commonSituations":"Pasting a goofish.com item URL (https://www.goofish.com/item?id=123...) instead of extracting the id query param, copying an ID with trailing spaces/invisible characters, or confusing numeric item IDs with alphanumeric share codes.","solutions":["Pass only the digits of the ID, e.g. xianyu item 812345678901","Extract the id query parameter from an item URL instead of pasting the whole URL","Trim whitespace/control characters from the value before passing it","Confirm you are not using a share token or short code in place of the numeric ID"],"exampleFix":"// before\nxianyu item 'https://www.goofish.com/item?id=812345678901'\n// after\nxianyu item 812345678901","handlingStrategy":"validation","validationCode":"function assertNumericId(v){ const s=String(v??'').trim(); if(!/^\\d+$/.test(s)) throw new Error(`ID must be numeric digits, got: ${v}`); return s; }\nconst id = assertNumericId(rawId);","typeGuard":"const isNumericId = (v) => typeof v === 'string' || typeof v === 'number' ? /^\\d+$/.test(String(v).trim()) : false;","tryCatchPattern":"try { await xianyuItem(id); } catch (e) { if (e instanceof ArgumentError && /must be a numeric ID/.test(e.message)) { const m = String(rawId).match(/[?&]id=(\\d+)/); if (m) return xianyuItem(m[1]); } throw e; }","preventionTips":["Extract the numeric id from item URLs (the ?id= query param) instead of pasting the URL","Trim whitespace and copy IDs without surrounding characters","Never pass share codes, short links, or decimal/negative numbers as IDs"],"tags":["argument-validation","cli","id-parsing"],"backgroundTag":"invalid-id-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}