{"record":{"id":"49ef0ce8a6a947c2","repo":"jackwener/OpenCLI","slug":"juejin-label-cannot-be-empty","errorCode":null,"errorMessage":"juejin ${label} cannot be empty","messagePattern":"juejin (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/juejin/utils.js","lineNumber":29,"sourceCode":"const UA = 'opencli-juejin-adapter (+https://github.com/jackwener/opencli)';\n\n// Juejin content / article IDs are 19-digit numeric strings.\nconst JUEJIN_ID = /^\\d{16,20}$/;\n\n// Top-level categories surfaced by `query_category_briefs`. The slugs are\n// stable so the adapter accepts a friendly name in addition to the raw id.\nexport const CATEGORY_ALIASES = {\n    backend: '6809637769959178254',\n    frontend: '6809637767543259144',\n    android: '6809635626879549454',\n    ios: '6809635626661445640',\n    ai: '6809637773935378440',\n};\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) {\n        throw new ArgumentError(`juejin ${label} cannot be empty`);\n    }\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    let n;\n    if (typeof raw === 'number') {\n        n = raw;\n    }\n    else if (typeof raw === 'string' && /^[1-9]\\d*$/.test(raw)) {\n        n = Number(raw);\n    }\n    else {\n        throw new ArgumentError(`juejin ${label} must be a positive decimal integer`);\n    }\n    if (!Number.isSafeInteger(n) || n <= 0) {\n        throw new ArgumentError(`juejin ${label} must be a positive integer`);","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/juejin/utils.js#L11-L47","documentation":"requireString is the Juejin CLI's generic required-argument validator. It throws an ArgumentError when a supplied argument (identified by label) is missing, null/undefined, or trims to an empty string. It fails fast so the CLI never sends empty identifiers to the API.","triggerScenarios":"Passing an empty or whitespace-only value for any argument routed through requireString, e.g. --user-id \"\" or --article-id \"  \", or omitting a required option so value is undefined.","commonSituations":"Shell variables that expand to empty (JUEJIN_ID=\"\" juejin article ...); copy-pasting a value with only whitespace; forgetting a required flag in a script; CI secrets not set so env interpolation yields ''.","solutions":["Supply a non-empty value for the flagged argument, e.g. --user-id 618471299904.","Check that the shell variable or CI secret actually contains a value (echo it before invoking).","Trim/paste the id again — leading/trailing whitespace is trimmed, but an all-whitespace value still fails.","Add a guard in your script: [ -n \"$MY_ID\" ] || { echo 'missing id'; exit 1; } before calling the CLI."],"exampleFix":"// before\njuejin recommend --user-id \"$USER_ID\"   # USER_ID empty\n// after\n: \"${USER_ID:?USER_ID must be set}\"\njuejin recommend --user-id \"$USER_ID\"","handlingStrategy":"validation","validationCode":"function requireNonEmpty(v, label){ const s = String(v ?? '').trim(); if (!s) throw new Error(label + ' is required and cannot be empty'); return s; }\n// call before invoking: requireNonEmpty(process.env.USER_ID, 'user-id')","typeGuard":"function isNonEmptyString(v){ return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n  cli({ userId: userIdArg });\n} catch (e) {\n  if (/cannot be empty/.test(e.message)) {\n    console.error(`Missing ${/juejin (.+) cannot be empty/.exec(e.message)[1]}; set it via flag or env.`);\n    process.exitCode = 2;\n    return;\n  }\n  throw e;\n}","preventionTips":["Validate env vars and shell inputs with ${VAR:?msg} or an upfront check before invoking the CLI.","Trim pasted ids; an all-whitespace value is treated as empty.","In scripts, assert all required ids are non-empty before composing the command line.","Keep CI secrets verified with a startup smoke check."],"tags":["argument-validation","cli","input-validation"],"backgroundTag":"missing-or-empty-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}