jackwener/OpenCLI · error · ArgumentError

semanticscholar paper id "${value}" is not recognised

Error message

semanticscholar paper id "${value}" is not recognised

What it means

requirePaperRef throws ArgumentError when the supplied reference is non-empty but matches none of the supported formats: 40-char hex paperId, Semantic Scholar paper URL, DOI (bare, `doi:`-prefixed, or doi.org URL), arXiv id (modern or legacy), or typed prefixes like ARXIV:/MAG:/ACL:/PMID:/PMCID:/URL:/CorpusId:/DBLP:. The error includes the offending value and lists accepted formats.

Source

Thrown at clis/semanticscholar/utils.js:77

    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`,
        'Use a Semantic Scholar paperId, a DOI, an arXiv id, or a prefixed id (e.g. "ARXIV:1706.03762", "PMID:12345").',
    );
}

/**
 * Fetch with optional `SEMANTIC_SCHOLAR_API_KEY` header. Retries once on 429
 * after a short pause; anonymous traffic hits the public ~100 req / 5 min
 * cap, and a single retry covers the typical burst-then-cool-down case.
 */
export async function s2Fetch(url, label) {
    const headers = { 'user-agent': UA, accept: 'application/json' };
    const apiKey = process.env.SEMANTIC_SCHOLAR_API_KEY;
    if (apiKey) headers['x-api-key'] = apiKey;

    let resp;
    let attempt = 0;
    while (true) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Convert to a supported form: bare DOI (`10.18653/v1/N19-1423`), arXiv id (`1706.03762`), or 40-char Semantic Scholar paperId.
  2. Use a typed prefix for other id systems, e.g. `PMID:12345`, `ACL:N19-1423`, `CorpusId:12345`.
  3. If you only have the title, search first: `opencli semanticscholar search "<title keywords>"` and use the returned paperId.
  4. Strip URL noise: for arxiv.org URLs use the id (`2401.01234`); for semanticscholar.org/paper URLs keep only the 40-hex segment.

Example fix

// before
opencli semanticscholar paper "https://arxiv.org/abs/1706.03762"
// after
opencli semanticscholar paper "ARXIV:1706.03762"
Defensive patterns

Strategy: validation

Validate before calling

const DOI = /^10\.\S+$/;
const ARXIV = /^\d{4}\.\d{4,5}(v\d+)?$/;
const S2ID = /^[0-9a-f]{40}$/i;
function looksLikePaperRef(v) {
    const s = String(v ?? '').trim();
    return S2ID.test(s) || DOI.test(s) || ARXIV.test(s) || /^(ARXIV|MAG|ACL|PMID|PMCID|URL|CorpusId|DBLP):/i.test(s);
}

Type guard

function isRecognizedPaperRef(v) {
    const s = String(v ?? '').trim();
    return /^[0-9a-f]{40}$/i.test(s) || /^10\.\S+$/.test(s) || /^\d{4}\.\d{4,5}(v\d+)?$/.test(s)
        || /^(ARXIV|MAG|ACL|PMID|PMCID|URL|CorpusId|DBLP):/i.test(s);
}

Try / catch

try {
    await fetchPaper(rawRef);
} catch (err) {
    if (err instanceof ArgumentError && /is not recognised/.test(err.message)) {
        console.error(`${err.message}\nHint: ${err.suggestion ?? 'use a DOI, arXiv id, or prefixed id'}`);
        process.exit(2);
    }
    throw err;
}

Prevention

When it happens

Trigger: Passing a raw paper title, a PubMed URL without PMID: prefix, an ISBN or SSRN id, an arXiv id missing its number part ('arXiv:'), a Semantic Scholar URL whose id is not 40-char hex, or a DOI lacking the `10.` prefix.

Common situations: Pasting a citation string instead of an identifier; using a dblp.org or arxiv.org URL rather than the bare id; typos in DOIs (missing '10.'); old Semantic Scholar URLs with a short legacy id.

Related errors


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