jackwener/OpenCLI · error · ArgumentError
pubmed ${label} must be one of: ${choices.join(', ')}
Error message
pubmed ${label} must be one of: ${choices.join(', ')} What it means
requireChoice validates enum-like options (position, sort, direction) against an allowed list, after applying the default. Values outside the list throw ArgumentError 'pubmed <label> must be one of: <choice1, choice2, ...>'.
Source
Thrown at clis/pubmed/utils.js:56
}
return n;
}
export function requireYear(value, label) {
if (value === undefined || value === null || value === '') {
return undefined;
}
const year = requireBoundedInt(value, 1900, 3000, label);
if (year < 1800) {
throw new ArgumentError(`pubmed ${label} must be >= 1800`);
}
return year;
}
export function requireChoice(value, choices, label, defaultValue) {
const text = String(value ?? defaultValue).trim();
if (!choices.includes(text)) {
throw new ArgumentError(`pubmed ${label} must be one of: ${choices.join(', ')}`);
}
return text;
}
export function buildEutilsUrl(tool, params = {}) {
const searchParams = new URLSearchParams();
searchParams.set('db', 'pubmed');
if (!params.retmode) {
searchParams.set('retmode', 'json');
}
if (process.env.NCBI_API_KEY) {
searchParams.set('api_key', process.env.NCBI_API_KEY);
}
if (process.env.NCBI_EMAIL) {
searchParams.set('email', process.env.NCBI_EMAIL);
}
for (const [key, value] of Object.entries(params)) {
if (value !== undefined && value !== null && value !== '') {View on GitHub (pinned to 49907e53dc)
Solutions
- Use exactly one of the values listed in the error message (they are comma-joined)
- Run the command with --help to see documented choices
- Match the exact casing of the allowed values
Example fix
// before --direction ascending // after --direction asc // or whichever value the error lists
Defensive patterns
Strategy: validation
Validate before calling
const ALLOWED_SORT = ['relevance', 'pub_date']; // see --help
if (!ALLOWED_SORT.includes(sort)) {
throw new Error(`sort must be one of: ${ALLOWED_SORT.join(', ')}`);
} Type guard
function isOneOf(v, choices) {
return choices.includes(String(v ?? '').trim());
} Try / catch
try {
await pubmedSearch(query, { sort });
} catch (err) {
const m = /must be one of: (.+)/.exec(err.message ?? '');
if (err instanceof ArgumentError && m) {
console.error(`Invalid sort '${sort}'. Allowed: ${m[1]}`);
process.exitCode = 2;
} else { throw err; }
} Prevention
- Use exactly the values listed in --help or the error message
- Watch for case sensitivity and abbreviations (asc vs ascending)
- Do not copy enum flags between different CLIs without checking
When it happens
Trigger: `--sort newest` when only 'relevance'/'pub_date' style values are accepted, `--direction ascending` instead of 'asc', misspelled position values.
Common situations: Guessing option names without reading --help, copying flags from a different CLI, case mismatches ('ASC' vs 'asc').
Related errors
- bilibili comments limit must be an integer between 1 and ${M
- bilibili comments parent must be a positive integer rpid
- boss ${name} must be <= ${max}
- ${label} must be a positive integer
- prompt is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/591f79b966841626.
Report an issue: GitHub.