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
- Provide an arXiv id positionally: opencli hf paper 1706.03762.
- Ensure the value is non-empty after trimming (no bare spaces).
- In scripts, guard the variable: : "${PAPER_ID:?PAPER_ID is required}" before invoking.
- 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
- Always quote positional args: opencli hf paper "$ID".
- Default-check shell variables with ${ID:?msg} before invoking.
- Never rely on prompts — the id is a required positional argument.
- Trim user-supplied input before passing it through.
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
- keyword must not be empty
- <from> station must not be empty
- <to> station must not be empty
- who 不能为空
- key is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/0858f347f2b416a0.
Report an issue: GitHub.