jackwener/OpenCLI · warning · ArgumentError
pubmed year-from must be <= year-to
Error message
pubmed year-from must be <= year-to
What it means
This ArgumentError is thrown by the `pubmed journal` command when the optional `--year-from` value is greater than `--year-to`. The command builds a PubMed [PDAT] date-range query and refuses to send a malformed range to the NCBI E-utilities API. It is an input-validation error, not a network failure.
Source
Thrown at clis/pubmed/journal.js:40
{ name: 'journal', positional: true, required: true, help: 'Journal name, e.g. "Nature" or "The Lancet"' },
{ name: 'limit', type: 'int', default: 20, help: 'Max results (1-100)' },
{ name: 'year-from', type: 'int', help: 'Filter publication year from' },
{ name: 'year-to', type: 'int', help: 'Filter publication year to' },
{ name: 'sort', default: 'relevance', choices: ['relevance', 'date'], help: 'Sort by relevance or date' },
],
columns: SEARCH_COLUMNS,
func: async (args) => {
const journal = requireText(args.journal, 'journal');
const limit = requireBoundedInt(args.limit, 20, 100);
const yearFrom = requireYear(args['year-from'], 'year-from');
const yearTo = requireYear(args['year-to'], 'year-to');
const sort = requireChoice(args.sort, ['relevance', 'date'], 'sort', 'relevance');
const terms = [`${journal}[Journal]`];
if (yearFrom || yearTo) {
const from = yearFrom || 1800;
const to = yearTo || new Date().getFullYear();
if (from > to) {
throw new ArgumentError('pubmed year-from must be <= year-to');
}
terms.push(`${from}:${to}[PDAT]`);
}
const esearch = await eutilsFetch('esearch', {
term: terms.join(' AND '),
retmax: limit,
usehistory: 'y',
sort: sort === 'date' ? 'pub_date' : '',
}, { label: 'pubmed journal' });
const pmids = esearch?.esearchresult?.idlist;
if (!Array.isArray(pmids)) {
throw new CommandExecutionError('pubmed journal did not return an id list', 'PubMed ESearch response shape may have changed.');
}
if (pmids.length === 0) {
throw new EmptyResultError('pubmed journal', `No articles found for journal "${journal}".`);
}
return fetchSummaryRows(pmids, 'pubmed journal summary');
},View on GitHub (pinned to 49907e53dc)
Solutions
- Swap the values so year-from <= year-to before invoking the command
- Clamp or validate user-supplied years in your script (e.g. from <= to, both 4-digit years within 1800..current year)
- Pass only one of the two flags if you just want articles from a year onwards or up to a year
Example fix
// before
clis.pubmedJournal({ journal: 'Nature', yearFrom: 2023, yearTo: 2018 });
// after
const from = Math.min(2023, 2018), to = Math.max(2023, 2018);
clis.pubmedJournal({ journal: 'Nature', yearFrom: from, yearTo: to }); Defensive patterns
Strategy: validation
Validate before calling
function validateYearRange(yearFrom, yearTo) {
const now = new Date().getFullYear();
const from = yearFrom ?? 1800;
const to = yearTo ?? now;
if (!Number.isInteger(from) || !Number.isInteger(to)) throw new TypeError('years must be integers');
if (from < 1800 || to > now) throw new RangeError('years out of range');
if (from > to) throw new RangeError(`year-from (${from}) must be <= year-to (${to})`);
} Try / catch
try {
await clis.pubmedJournal({ journal, yearFrom, yearTo });
} catch (e) {
if (e.name === 'ArgumentError' && /year-from/.test(e.message)) {
[yearFrom, yearTo] = [yearTo, yearFrom]; // or surface a friendly message
} else throw e;
} Prevention
- Always validate from <= to in CLI wrappers before calling the command
- Default missing bounds the same way the library does (1800 / current year) when previewing
- Swap values instead of erroring when order does not matter to your UX
- Unit-test year-range inputs including edge years (1800, future years)
When it happens
Trigger: Running the journal command with yearFrom later than yearTo, e.g. `--year-from 2023 --year-to 2019`. Also occurs when only one of the two is set and defaults collide: yearFrom=2050 with no yearTo (to defaults to current year), or yearTo=1800 with no yearFrom (from defaults to 1800).
Common situations: Typo swapping the from/to flags on the command line; scripting that passes user-supplied years unvalidated; passing a future year as year-from; accidentally passing year-to into year-from.
Related errors
- pubmed ${label} must be >= 1800
- pubmed year-from must be <= year-to
- ${label} must be a positive integer
- ${label} must be an integer >= ${min}
- Invalid Lobsters short_id: ${args.id}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/875c33b73ffd34e6.
Report an issue: GitHub.