{"record":{"id":"4375ddf3d24abb87","repo":"jackwener/OpenCLI","slug":"semanticscholar-paper-id-cannot-be-empty","errorCode":null,"errorMessage":"semanticscholar paper id cannot be empty","messagePattern":"semanticscholar paper id cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/semanticscholar/utils.js","lineNumber":60,"sourceCode":"    }\n    return n;\n}\n\n/**\n * Resolve a user-supplied paper reference to a Semantic Scholar paper id\n * segment. Accepts:\n *\n *   - bare Semantic Scholar paperId (40-char hex)\n *   - DOI (with or without `doi:` / `https://doi.org/` prefix)\n *   - arXiv id (`1706.03762` / `1706.03762v3` / `cs/0501067`)\n *   - typed prefixes Semantic Scholar accepts verbatim (`ARXIV:`, `MAG:`,\n *     `ACL:`, `PMID:`, `PMCID:`, `URL:`, `CorpusId:`, `DBLP:`)\n *   - full `https://www.semanticscholar.org/paper/<paperId>` URL\n */\nexport function requirePaperRef(value) {\n    const raw = String(value ?? '').trim();\n    if (!raw) {\n        throw new ArgumentError(\n            'semanticscholar paper id cannot be empty',\n            'Example: opencli semanticscholar paper 10.18653/v1/N19-1423',\n        );\n    }\n    const s2Url = raw.match(/^https?:\\/\\/(?:www\\.)?semanticscholar\\.org\\/paper\\/(?:[^/]+\\/)?([0-9a-f]{40})/i);\n    if (s2Url) return s2Url[1].toLowerCase();\n    if (S2_PAPER_ID.test(raw)) return raw.toLowerCase();\n    if (PREFIXED.test(raw)) return raw;\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    const doiUrl = raw.match(/^https?:\\/\\/(?:dx\\.)?doi\\.org\\/(.+)$/i);\n    if (doiUrl && DOI_BARE.test(doiUrl[1])) return `DOI:${doiUrl[1]}`;\n    if (DOI_BARE.test(raw)) return `DOI:${raw}`;\n    if (ARXIV_MODERN.test(raw) || ARXIV_LEGACY.test(raw)) return `ARXIV:${raw}`;\n    throw new ArgumentError(\n        `semanticscholar paper id \"${value}\" is not recognised`,","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/semanticscholar/utils.js#L42-L78","documentation":"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.","triggerScenarios":"Running `opencli semanticscholar paper` with no ref argument, or passing an empty string, whitespace, or an undefined shell variable as the paper reference.","commonSituations":"Scripts iterating over a list where an entry is blank; forgot to paste the id/DOI; variable interpolation ($REF unset) producing an empty argument.","solutions":["Re-run with an actual reference, e.g. `opencli semanticscholar paper 10.18653/v1/N19-1423`.","Use an arXiv id or Semantic Scholar URL if you do not have a DOI (requirePaperRef accepts them).","In scripts, skip or error on blank entries before invoking the CLI."],"exampleFix":"// before\nopencli semanticscholar paper \"$REF\"   # REF empty -> error\n// after\n: \"${REF:?REF must be set to a paper id or DOI}\"\nopencli semanticscholar paper \"$REF\"","handlingStrategy":"validation","validationCode":"const ref = (process.argv[3] ?? '').trim();\nif (!ref) { console.error('usage: opencli semanticscholar paper <paperId|DOI|arXiv id|URL>'); process.exit(1); }","typeGuard":"function isNonEmptyRef(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n    await fetchPaper(args.ref);\n} catch (err) {\n    if (err instanceof ArgumentError && /paper id cannot be empty/.test(err.message)) {\n        console.error('Provide a paper reference, e.g. 10.18653/v1/N19-1423');\n        process.exit(2);\n    }\n    throw err;\n}","preventionTips":["Guard shell variables with ${REF:?REF is required} before invoking the CLI.","Filter blank lines when batching references from a file: grep -v '^$'.","Quote every argument to prevent empty-token splitting.","Print usage on argc checks before calling the command."],"tags":["argument-validation","cli","input"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}