jackwener/OpenCLI · error · ArgumentError

juejin ${label} cannot be empty

Error message

juejin ${label} cannot be empty

What it means

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.

Source

Thrown at clis/juejin/utils.js:29

const UA = 'opencli-juejin-adapter (+https://github.com/jackwener/opencli)';

// Juejin content / article IDs are 19-digit numeric strings.
const JUEJIN_ID = /^\d{16,20}$/;

// Top-level categories surfaced by `query_category_briefs`. The slugs are
// stable so the adapter accepts a friendly name in addition to the raw id.
export const CATEGORY_ALIASES = {
    backend: '6809637769959178254',
    frontend: '6809637767543259144',
    android: '6809635626879549454',
    ios: '6809635626661445640',
    ai: '6809637773935378440',
};

export function requireString(value, label) {
    const s = String(value ?? '').trim();
    if (!s) {
        throw new ArgumentError(`juejin ${label} cannot be empty`);
    }
    return s;
}

export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
    const raw = value ?? defaultValue;
    let n;
    if (typeof raw === 'number') {
        n = raw;
    }
    else if (typeof raw === 'string' && /^[1-9]\d*$/.test(raw)) {
        n = Number(raw);
    }
    else {
        throw new ArgumentError(`juejin ${label} must be a positive decimal integer`);
    }
    if (!Number.isSafeInteger(n) || n <= 0) {
        throw new ArgumentError(`juejin ${label} must be a positive integer`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Supply a non-empty value for the flagged argument, e.g. --user-id 618471299904.
  2. Check that the shell variable or CI secret actually contains a value (echo it before invoking).
  3. Trim/paste the id again — leading/trailing whitespace is trimmed, but an all-whitespace value still fails.
  4. Add a guard in your script: [ -n "$MY_ID" ] || { echo 'missing id'; exit 1; } before calling the CLI.

Example fix

// before
juejin recommend --user-id "$USER_ID"   # USER_ID empty
// after
: "${USER_ID:?USER_ID must be set}"
juejin recommend --user-id "$USER_ID"
Defensive patterns

Strategy: validation

Validate before calling

function requireNonEmpty(v, label){ const s = String(v ?? '').trim(); if (!s) throw new Error(label + ' is required and cannot be empty'); return s; }
// call before invoking: requireNonEmpty(process.env.USER_ID, 'user-id')

Type guard

function isNonEmptyString(v){ return typeof v === 'string' && v.trim().length > 0; }

Try / catch

try {
  cli({ userId: userIdArg });
} catch (e) {
  if (/cannot be empty/.test(e.message)) {
    console.error(`Missing ${/juejin (.+) cannot be empty/.exec(e.message)[1]}; set it via flag or env.`);
    process.exitCode = 2;
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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 ''.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/49ef0ce8a6a947c2. Report an issue: GitHub.