jackwener/OpenCLI · error · ArgumentError

arxiv author cannot be empty

Error message

arxiv author cannot be empty

What it means

An ArgumentError thrown before any network call when the `author` argument to `arxiv author` is missing, empty, or whitespace-only. The library validates input early so users get a precise message (with an example) instead of a confusing empty-result or API error from arXiv. It is pure input validation — nothing was sent to arXiv.

Source

Thrown at clis/arxiv/author.js:25

import { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors';
import { arxivFetch, normalizeArxivLimit, parseEntries } from './utils.js';

cli({
    site: 'arxiv',
    name: 'author',
    access: 'read',
    description: 'List arXiv papers by a given author (newest first)',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'author', positional: true, required: true, help: 'Author name (e.g. "Yoshua Bengio" or "Y Bengio")' },
        { name: 'limit', type: 'int', default: 20, help: 'Max papers to return (max 50)' },
    ],
    columns: ['id', 'title', 'authors', 'published', 'primary_category', 'url'],
    func: async (args) => {
        const authorText = String(args.author || '').trim();
        if (!authorText) {
            throw new ArgumentError('arxiv author cannot be empty', 'Example: opencli arxiv author "Yoshua Bengio"');
        }
        const limit = normalizeArxivLimit(args.limit, 20, 50);
        // Quote the value so multi-word author names match as a phrase.
        const query = encodeURIComponent(`au:"${authorText}"`);
        const xml = await arxivFetch(`search_query=${query}&max_results=${limit}&sortBy=submittedDate&sortOrder=descending`);
        const entries = parseEntries(xml);
        if (!entries.length) {
            throw new EmptyResultError('arxiv author', `No papers found for author "${authorText}". Try alternate spellings (e.g. initials).`);
        }
        return entries.map(e => ({
            id: e.id,
            title: e.title,
            authors: e.authors,
            published: e.published,
            primary_category: e.primary_category,
            url: e.url,
        }));
    },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the author name in quotes: opencli arxiv author "Yoshua Bengio"
  2. Check the shell command for quoting/escaping mistakes that swallowed the argument
  3. If driven by a script/variable, verify the variable is non-empty before invoking
  4. Use the documented example format shown in the error hint

Example fix

// before
run(`opencli arxiv author ${name}`); // name may be empty
// after
if (!name?.trim()) throw new Error('author name is required');
run(`opencli arxiv author "${name.trim()}"`);
Defensive patterns

Strategy: validation

Validate before calling

const author = String(process.argv[2] || '').trim();
if (!author) throw new Error('Usage: opencli arxiv author "<author name>"');

Type guard

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

Try / catch

try {
  await exec('opencli arxiv author ' + JSON.stringify(author));
} catch (e) {
  if (e.message.includes('author cannot be empty')) {
    console.error('Provide a quoted author name, e.g. opencli arxiv author "Yoshua Bengio"');
    process.exitCode = 1;
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `opencli arxiv author` with no argument, `--author ""`, or `--author " "`; quoting mistakes in the shell that drop the argument entirely.

Common situations: Shell quoting errors (unescaped spaces collapsing args); scripting with a variable that is empty because an upstream lookup failed; forgetting the positional argument.

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/19e143c06c812dd7. Report an issue: GitHub.