jackwener/OpenCLI · error · ArgumentError

juejin category "${value}" is not recognised

Error message

juejin category "${value}" is not recognised

What it means

resolveCategory maps a user-supplied --category value (numeric category id or human-friendly slug like 'backend') to Juejin's internal category id. If the trimmed value is neither a valid Juejin id nor a known alias key, an ArgumentError is thrown with a hint listing accepted slugs and an example id.

Source

Thrown at clis/juejin/utils.js:75

    if (typeof raw === 'number') {
        if (Number.isSafeInteger(raw) && raw >= 0) return String(raw);
        throw new ArgumentError('juejin cursor must be a non-negative decimal integer');
    }
    if (typeof raw === 'string' && /^(0|[1-9]\d*)$/.test(raw)) {
        return raw;
    }
    throw new ArgumentError('juejin cursor must be a non-negative decimal integer');
}

/** Resolve a `--category` arg to the underlying numeric category id. */
export function resolveCategory(value) {
    if (value == null) return '';
    const raw = String(value).trim();
    if (!raw) return '';
    if (JUEJIN_ID.test(raw)) return raw;
    const slug = raw.toLowerCase();
    if (CATEGORY_ALIASES[slug]) return CATEGORY_ALIASES[slug];
    throw new ArgumentError(
        `juejin category "${value}" is not recognised`,
        `Use a category id (e.g. "${CATEGORY_ALIASES.backend}") or one of: ${Object.keys(CATEGORY_ALIASES).join(', ')}.`,
    );
}

/**
 * POST JSON to a Juejin endpoint. The API returns `{ err_no, err_msg, data }`;
 * a non-zero `err_no` is surfaced as a typed `CommandExecutionError`.
 */
export async function juejinFetch(path, body, label, method = 'POST') {
    const url = `${JUEJIN_API_BASE}${path}`;
    let resp;
    try {
        const init = {
            method,
            headers: { 'user-agent': UA, accept: 'application/json' },
        };
        if (method === 'POST') {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use one of the listed alias slugs, e.g. --category backend (the error hint enumerates all valid keys).
  2. Use a valid numeric category id (the JUEJIN_ID format) copied from a Juejin category URL.
  3. Run the CLI's help to see the accepted category names for your installed version.
  4. Update the CLI if a new Juejin category was added after your version's alias table was written; otherwise contribute the alias to CATEGORY_ALIASES.

Example fix

// before
cli({ category: 'front-end' }); // not an alias
// after
cli({ category: 'frontend' }); // valid alias in CATEGORY_ALIASES
// or
cli({ category: '6809637773935378440' }); // raw id
Defensive patterns

Strategy: validation

Validate before calling

const VALID = new Set(['backend','frontend','android','ios','ai','devops','codepig']); // mirror CATEGORY_ALIASES
function resolveCat(v){ if (v == null) return ''; const s = String(v).trim(); if (!s) return ''; if (/^\d+$/.test(s)) return s; if (VALID.has(s.toLowerCase())) return s; throw new Error(`unknown category "${v}"; use one of: ${[...VALID].join(', ')}`); }

Type guard

function isKnownCategory(v){ if (v == null) return true; const s = String(v).trim().toLowerCase(); return /^\d+$/.test(s) || VALID.has(s); }

Try / catch

try {
  cli({ category });
} catch (e) {
  if (/is not recognised/.test(e.message)) {
    console.error(e.message); // hint lists accepted slugs
    cli({ category: 'backend' });
  } else throw e;
}

Prevention

When it happens

Trigger: Passing an unknown --category value such as --category frontend2, --category "Front End", --category "ai-ml", a misspelled slug, or an id from a different Juejin entity (e.g. a tag id or user id).

Common situations: Guessing slug names instead of checking --help (aliases are snake_case like 'backend', 'frontend', 'android', 'ios', 'ai', 'codepig' etc. per CATEGORY_ALIASES); using an article/tag id rather than a category id; renaming drift after the alias table changed between CLI versions.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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