{"record":{"id":"c40c5f4ab392fe42","repo":"jackwener/OpenCLI","slug":"openalex-work-id-value-is-not-recognised","errorCode":null,"errorMessage":"openalex work id \"${value}\" is not recognised","messagePattern":"openalex work id \"(.+?)\" is not recognised","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/openalex/utils.js","lineNumber":75,"sourceCode":"    // 2) bare W… id\n    if (WORK_ID.test(raw.toUpperCase())) {\n        return raw.toUpperCase();\n    }\n    // 3) doi:… prefix\n    if (/^doi:/i.test(raw)) {\n        const doi = raw.replace(/^doi:/i, '').trim();\n        if (DOI_BARE.test(doi)) return `doi:${doi}`;\n    }\n    // 4) full doi URL\n    const doiUrl = raw.match(/^https?:\\/\\/(?:dx\\.)?doi\\.org\\/(.+)$/i);\n    if (doiUrl && DOI_BARE.test(doiUrl[1])) {\n        return `doi:${doiUrl[1]}`;\n    }\n    // 5) bare 10.xxxx/yyy DOI\n    if (DOI_BARE.test(raw)) {\n        return `doi:${raw}`;\n    }\n    throw new ArgumentError(\n        `openalex work id \"${value}\" is not recognised`,\n        'Use a Work id (\"W2741809807\"), a DOI (\"10.7717/peerj.4375\"), or a full openalex.org / doi.org URL.',\n    );\n}\n\nexport async function openalexFetch(url, label) {\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that api.openalex.org is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `OpenAlex returned 404 for ${url}.`);","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/openalex/utils.js#L57-L93","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","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"],"exampleFix":"// before\nawait work('Attention Is All You Need'); // title, not an ID\n// after\nconst [hit] = await search('attention is all you need');\nawait work(hit.id); // e.g. 'W2963403828'","handlingStrategy":"validation","validationCode":"function isRecognizedWorkRef(v) {\n  const s = String(v ?? '').trim();\n  return /^W\\d{4,}$/i.test(s)\n    || /^10\\.\\S+$/.test(s)\n    || /^https?:\\/\\/(?:api\\.)?openalex\\.org\\//i.test(s)\n    || /^https?:\\/\\/doi\\.org\\//i.test(s);\n}\nif (!isRecognizedWorkRef(ref)) throw new Error('Use a W-id, DOI, or openalex/doi.org URL');","typeGuard":"function isWorkRef(v) {\n  const s = String(v ?? '').trim();\n  return /^W\\d{4,}$/.test(s.toUpperCase()) || /^10\\.\\S+$/.test(s);\n}","tryCatchPattern":"try {\n  await work(ref);\n} catch (e) {\n  if (e.name === 'ArgumentError' && e.message.includes('is not recognised')) {\n    console.error('Unrecognized ref format; use W-id, DOI, or a full URL');\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["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"],"tags":["openalex","argument-validation","invalid-identifier-format"],"backgroundTag":"invalid-resource-id","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}