jackwener/OpenCLI · error · ArgumentError

hf paper id cannot be empty

Error message

hf paper id cannot be empty

What it means

ArgumentError('hf paper id cannot be empty') thrown at clis/hf/paper.js:24 when the required positional `id` argument is missing, an empty string, or whitespace-only after trim(). The library requires an arXiv id because it fetches a single paper detail from the HF /api/papers/<id> endpoint.

Source

Thrown at clis/hf/paper.js:24

const ARXIV_ID_PATTERN = /^\d{4}\.\d{4,5}(?:v\d+)?$/;

cli({
    site: 'hf',
    name: 'paper',
    access: 'read',
    description: 'Hugging Face paper detail by arXiv id (full title / summary / authors / AI keywords)',
    domain: 'huggingface.co',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'id', positional: true, required: true, help: 'arXiv id (e.g. "1706.03762") — same value HF uses to mirror the paper' },
    ],
    columns: ['id', 'title', 'authors', 'publishedAt', 'upvotes', 'aiKeywords', 'summary', 'aiSummary', 'url'],
    func: async (args) => {
        const raw = String(args.id ?? '').trim();
        if (!raw) {
            throw new ArgumentError('hf paper id cannot be empty', 'Example: opencli hf paper 1706.03762');
        }
        if (!ARXIV_ID_PATTERN.test(raw)) {
            throw new ArgumentError(
                `hf paper id "${args.id}" is not a valid arXiv id`,
                'Expected the modern arXiv form `YYMM.NNNNN` (optionally with a version suffix like `v3`).',
            );
        }
        const endpoint = process.env.HF_ENDPOINT?.replace(/\/+$/, '') || 'https://huggingface.co';
        const url = `${endpoint}/api/papers/${encodeURIComponent(raw)}`;
        let resp;
        try {
            resp = await fetch(url, { headers: { accept: 'application/json' } });
        }
        catch (err) {
            throw new CommandExecutionError(`hf paper request failed: ${err?.message ?? err}`);
        }
        if (resp.status === 404) {
            throw new EmptyResultError('hf paper', `Hugging Face has no paper page for "${raw}".`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide an arXiv id positionally: opencli hf paper 1706.03762.
  2. Ensure the value is non-empty after trimming (no bare spaces).
  3. In scripts, guard the variable: : "${PAPER_ID:?PAPER_ID is required}" before invoking.
  4. Use `opencli hf paper --help` to see the required positional `id` argument.

Example fix

// before
opencli hf paper $ID            # ID unset -> empty arg
// after
opencli hf paper "${ID:?arXiv id required}"
Defensive patterns

Strategy: validation

Validate before calling

function validatePaperId(raw) {
  const id = String(raw ?? '').trim();
  if (!id) throw new Error('arXiv id is required, e.g. 1706.03762');
  return id;
}
// shell: : "${PAPER_ID:?PAPER_ID is required}"

Type guard

const hasPaperId = (v) => typeof v === 'string' && v.trim().length > 0;

Try / catch

try {
  await run(`hf paper ${id}`);
} catch (e) {
  if (String(e.message).includes('id cannot be empty')) {
    console.error('Usage: opencli hf paper <arxiv-id>  e.g. opencli hf paper 1706.03762');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `opencli hf paper` with no positional argument; passing an empty string (--id '' or id=""); passing only whitespace (' '); a shell variable interpolating to empty (id="$PAPER_ID" with PAPER_ID unset) so String(args.id ?? '').trim() yields ''.

Common situations: Forgetting the positional argument because the user expected an interactive prompt; unquoted variable expansion producing an empty argument in scripts; copy-paste losing the id; wrapper scripts not propagating arguments (missing "$@").

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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