jackwener/OpenCLI · error · ArgumentError
openalex work id "${value}" is not recognised
Error message
openalex work id "${value}" is not recognised What it means
This is requireWorkRef's terminal rejection: the input matched none of the accepted forms (full OpenAlex URL, bare W-id, doi.org URL, or bare 10.x/yyy DOI), so an ArgumentError is thrown with a hint listing valid formats. It exists so malformed identifiers fail fast with actionable guidance instead of producing a confusing upstream 404.
Source
Thrown at clis/openalex/utils.js:75
// 2) bare W… id
if (WORK_ID.test(raw.toUpperCase())) {
return raw.toUpperCase();
}
// 3) doi:… prefix
if (/^doi:/i.test(raw)) {
const doi = raw.replace(/^doi:/i, '').trim();
if (DOI_BARE.test(doi)) return `doi:${doi}`;
}
// 4) full doi URL
const doiUrl = raw.match(/^https?:\/\/(?:dx\.)?doi\.org\/(.+)$/i);
if (doiUrl && DOI_BARE.test(doiUrl[1])) {
return `doi:${doiUrl[1]}`;
}
// 5) bare 10.xxxx/yyy DOI
if (DOI_BARE.test(raw)) {
return `doi:${raw}`;
}
throw new ArgumentError(
`openalex work id "${value}" is not recognised`,
'Use a Work id ("W2741809807"), a DOI ("10.7717/peerj.4375"), or a full openalex.org / doi.org URL.',
);
}
export async function openalexFetch(url, label) {
let resp;
try {
resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });
}
catch (err) {
throw new CommandExecutionError(
`${label} request failed: ${err?.message ?? err}`,
'Check that api.openalex.org is reachable from this network.',
);
}
if (resp.status === 404) {
throw new EmptyResultError(label, `OpenAlex returned 404 for ${url}.`);View on GitHub (pinned to 49907e53dc)
Solutions
- Convert the identifier to a supported form: W-id or DOI
- Resolve the title via the openalex search command first, then use the returned W-id/DOI
- Check the ID wasn't truncated or altered during copy-paste
- arXiv IDs are not supported — find the paper's DOI (e.g. via search) instead
Example fix
// before
await work('Attention Is All You Need'); // title, not an ID
// after
const [hit] = await search('attention is all you need');
await work(hit.id); // e.g. 'W2963403828' Defensive patterns
Strategy: validation
Validate before calling
function isRecognizedWorkRef(v) {
const s = String(v ?? '').trim();
return /^W\d{4,}$/i.test(s)
|| /^10\.\S+$/.test(s)
|| /^https?:\/\/(?:api\.)?openalex\.org\//i.test(s)
|| /^https?:\/\/doi\.org\//i.test(s);
}
if (!isRecognizedWorkRef(ref)) throw new Error('Use a W-id, DOI, or openalex/doi.org URL'); Type guard
function isWorkRef(v) {
const s = String(v ?? '').trim();
return /^W\d{4,}$/.test(s.toUpperCase()) || /^10\.\S+$/.test(s);
} Try / catch
try {
await work(ref);
} catch (e) {
if (e.name === 'ArgumentError' && e.message.includes('is not recognised')) {
console.error('Unrecognized ref format; use W-id, DOI, or a full URL');
process.exitCode = 2;
} else throw e;
} Prevention
- Resolve titles/arXiv ids via search first, then pass the returned W-id
- Validate the ref against /^W\d{4,}$/ or /^10\./ before calling
- Check for truncation when copying long DOIs
When it happens
Trigger: Passing a title string, PMID, arXiv ID, semantic-scholar ID, a W-id with too few digits (WORK_ID requires W plus >=4 digits), or any random string as the work `ref`.
Common situations: Pasting a paper title or an arXiv id like '2301.07041' expecting lookup; truncating a W-id during copy-paste so it has fewer than 4 digits; confusing PubMed/Scopus IDs with OpenAlex IDs; passing a DOI missing its '10.' prefix.
Related errors
- openalex ${label} cannot be empty
- openalex ${label} must be a positive integer
- openalex ${label} must be <= ${maxValue}
- openalex work id is required (e.g. "W2741809807", "10.7717/p
- openalex work id "${value}" must be a Work (W…) ID, got "${i
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c40c5f4ab392fe42.
Report an issue: GitHub.