jackwener/OpenCLI · error · ArgumentError

semanticscholar paper id cannot be empty

Error message

semanticscholar paper id cannot be empty

What it means

requirePaperRef resolves a user-supplied paper reference to a Semantic Scholar paper id; it throws ArgumentError with an example usage when the reference is empty after trimming. It fails fast so the CLI can print a concrete example instead of issuing a doomed API request.

Source

Thrown at clis/semanticscholar/utils.js:60

    }
    return n;
}

/**
 * Resolve a user-supplied paper reference to a Semantic Scholar paper id
 * segment. Accepts:
 *
 *   - bare Semantic Scholar paperId (40-char hex)
 *   - DOI (with or without `doi:` / `https://doi.org/` prefix)
 *   - arXiv id (`1706.03762` / `1706.03762v3` / `cs/0501067`)
 *   - typed prefixes Semantic Scholar accepts verbatim (`ARXIV:`, `MAG:`,
 *     `ACL:`, `PMID:`, `PMCID:`, `URL:`, `CorpusId:`, `DBLP:`)
 *   - full `https://www.semanticscholar.org/paper/<paperId>` URL
 */
export function requirePaperRef(value) {
    const raw = String(value ?? '').trim();
    if (!raw) {
        throw new ArgumentError(
            'semanticscholar paper id cannot be empty',
            'Example: opencli semanticscholar paper 10.18653/v1/N19-1423',
        );
    }
    const s2Url = raw.match(/^https?:\/\/(?:www\.)?semanticscholar\.org\/paper\/(?:[^/]+\/)?([0-9a-f]{40})/i);
    if (s2Url) return s2Url[1].toLowerCase();
    if (S2_PAPER_ID.test(raw)) return raw.toLowerCase();
    if (PREFIXED.test(raw)) return raw;
    if (/^doi:/i.test(raw)) {
        const doi = raw.replace(/^doi:/i, '').trim();
        if (DOI_BARE.test(doi)) return `DOI:${doi}`;
    }
    const doiUrl = raw.match(/^https?:\/\/(?:dx\.)?doi\.org\/(.+)$/i);
    if (doiUrl && DOI_BARE.test(doiUrl[1])) return `DOI:${doiUrl[1]}`;
    if (DOI_BARE.test(raw)) return `DOI:${raw}`;
    if (ARXIV_MODERN.test(raw) || ARXIV_LEGACY.test(raw)) return `ARXIV:${raw}`;
    throw new ArgumentError(
        `semanticscholar paper id "${value}" is not recognised`,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run with an actual reference, e.g. `opencli semanticscholar paper 10.18653/v1/N19-1423`.
  2. Use an arXiv id or Semantic Scholar URL if you do not have a DOI (requirePaperRef accepts them).
  3. In scripts, skip or error on blank entries before invoking the CLI.

Example fix

// before
opencli semanticscholar paper "$REF"   # REF empty -> error
// after
: "${REF:?REF must be set to a paper id or DOI}"
opencli semanticscholar paper "$REF"
Defensive patterns

Strategy: validation

Validate before calling

const ref = (process.argv[3] ?? '').trim();
if (!ref) { console.error('usage: opencli semanticscholar paper <paperId|DOI|arXiv id|URL>'); process.exit(1); }

Type guard

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

Try / catch

try {
    await fetchPaper(args.ref);
} catch (err) {
    if (err instanceof ArgumentError && /paper id cannot be empty/.test(err.message)) {
        console.error('Provide a paper reference, e.g. 10.18653/v1/N19-1423');
        process.exit(2);
    }
    throw err;
}

Prevention

When it happens

Trigger: Running `opencli semanticscholar paper` with no ref argument, or passing an empty string, whitespace, or an undefined shell variable as the paper reference.

Common situations: Scripts iterating over a list where an entry is blank; forgot to paste the id/DOI; variable interpolation ($REF unset) producing an empty 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/4375ddf3d24abb87. Report an issue: GitHub.