{"record":{"id":"242294794c2b503d","repo":"jackwener/OpenCLI","slug":"pubmed-label-cannot-be-empty","errorCode":null,"errorMessage":"pubmed ${label} cannot be empty","messagePattern":"pubmed (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/pubmed/utils.js","lineNumber":13,"sourceCode":"import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';\n\nexport const EUTILS_BASE = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils';\nexport const SEARCH_COLUMNS = ['rank', 'pmid', 'title', 'authors', 'journal', 'year', 'article_type', 'doi', 'url'];\nexport const LINK_COLUMNS = ['rank', 'pmid', 'title', 'authors', 'journal', 'year', 'article_type', 'doi', 'url'];\nexport const RELATED_COLUMNS = ['rank', 'pmid', 'title', 'authors', 'journal', 'year', 'article_type', 'score', 'doi', 'url'];\n\nlet lastRequestAt = 0;\n\nexport function requireText(value, label) {\n    const text = String(value ?? '').trim();\n    if (!text) {\n        throw new ArgumentError(`pubmed ${label} cannot be empty`);\n    }\n    return text;\n}\n\nexport function requirePmid(value, label = 'pmid') {\n    const pmid = requireText(value, label);\n    if (!/^\\d+$/.test(pmid)) {\n        throw new ArgumentError(`pubmed ${label} must be a numeric PMID`, 'Example: 37780221');\n    }\n    return pmid;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const text = String(raw).trim();\n    if (!/^\\d+$/.test(text)) {\n        throw new ArgumentError(`pubmed ${label} must be a positive integer`);\n    }","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pubmed/utils.js#L1-L31","documentation":"requireText is the shared validator for text arguments (name, query, journal, term, pmid, terms). It stringifies, trims, and throws ArgumentError 'pubmed <label> cannot be empty' when nothing remains, failing fast instead of sending a blank parameter to NCBI.","triggerScenarios":"Any pubmed command invoked with an empty, whitespace-only, null, or undefined text argument, e.g. `pubmed search \"\"` or `pubmed journal --name '   '`.","commonSituations":"Unset shell variables expanding to empty string, forgotten positional argument, empty config field, programmatic callers passing null/undefined.","solutions":["Provide a non-empty value for the labeled argument","Echo the shell variable or config field feeding the argument to confirm it is populated","Guard in calling scripts: abort before invoking when the value trims to empty"],"exampleFix":"// before\nconst q = process.env.QUERY; // may be undefined\nawait pubmedSearch(q);\n// after\nconst q = (process.env.QUERY ?? '').trim();\nif (!q) throw new Error('QUERY env var is required');\nawait pubmedSearch(q);","handlingStrategy":"validation","validationCode":"function assertNonEmpty(value, label) {\n  const t = String(value ?? '').trim();\n  if (!t) throw new Error(`pubmed ${label} cannot be empty`);\n  return t;\n}\nassertNonEmpty(query, 'query'); // call before invoking the command","typeGuard":"function isNonEmptyText(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await cli.parse(['pubmed', 'search', query]);\n} catch (err) {\n  if (err instanceof ArgumentError && /cannot be empty/.test(err.message)) {\n    console.error(`Missing value: ${err.message}`);\n    process.exitCode = 2;\n  } else { throw err; }\n}","preventionTips":["Always trim and check user input before passing CLI arguments","Default-fill or fail fast on unset env variables feeding arguments","Echo interpolated shell variables before running the command"],"tags":["validation","argument-error","empty-input","pubmed"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}