jackwener/OpenCLI · error · ArgumentError
weread-official: ${label} must be one of: ${choices.join(',
Error message
weread-official: ${label} must be one of: ${choices.join(', ')} What it means
requireChoice validates that a value is one of an enumerated set of allowed strings; if the trimmed text (after applying any defaultValue) is not in the choices array, it throws this ArgumentError listing the valid options. It is used by mode-type options to guarantee only supported modes reach the API layer.
Source
Thrown at clis/weread-official/utils.js:283
}
const text = String(value).trim();
if (!/^\d+$/.test(text)) {
throw new ArgumentError(`weread-official: ${label} must be a positive integer`);
}
const n = Number(text);
if (!Number.isSafeInteger(n) || n < 1) {
throw new ArgumentError(`weread-official: ${label} must be a positive integer`);
}
if (max !== undefined && n > max) {
throw new ArgumentError(`weread-official: ${label} must be <= ${max}`);
}
return n;
}
export function requireChoice(value, choices, label, defaultValue) {
const text = String(value ?? defaultValue ?? '').trim();
if (!choices.includes(text)) {
throw new ArgumentError(`weread-official: ${label} must be one of: ${choices.join(', ')}`);
}
return text;
}
// ── Empty-result helper ────────────────────────────────────────────────────
/** Throw EmptyResultError with a stable command label. */
export function emptyResult(command, hint) {
throw new EmptyResultError(`weread-official ${command}`, hint);
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Use exactly one of the listed choices from the error message, respecting case.
- Run the command with --help to see the current set of accepted modes.
- If upgrading from an older version, map the renamed mode to its new name.
- In scripts, validate against the same list before invoking, or pick from the choices programmatically.
Example fix
// before cli(['recommend', '--mode', 'Daily']); // after cli(['recommend', '--mode', 'daily']); // exact match of a listed choice
Defensive patterns
Strategy: validation
Validate before calling
const MODES = ['daily', 'weekly', 'monthly']; // match the command's choices
if (!MODES.includes(mode)) throw new Error(`mode must be one of: ${MODES.join(', ')}`); Type guard
function isValidMode(v, choices) { return choices.includes(String(v ?? '').trim()); } Try / catch
try {
await cli.run(['recommend', '--mode', mode]);
} catch (e) {
if (e instanceof ArgumentError && /must be one of:/.test(e.message)) {
const choices = e.message.split('must be one of: ')[1].split(', ');
console.error(`Invalid mode '${mode}'. Valid: ${choices.join(', ')}`); process.exitCode = 2;
} else throw e;
} Prevention
- Parse the allowed choices from the error message and validate interactively.
- Never hardcode mode strings copied from old scripts; verify against --help after upgrades.
- Keep enum values in a shared constant module used by both scripts and docs.
- Remember matching is exact and case-sensitive.
When it happens
Trigger: Passing --mode something to the mode option where 'something' is not in the choices array, or passing an empty value with no default configured.
Common situations: Misspelling a mode ('daily' vs 'day'); case mismatch ('Daily' vs 'daily' — matching is exact); using a mode removed or renamed in a newer CLI version.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- huodongxing eventType must be 1 (offline) or 2 (online)
- juejin category "${value}" is not recognised
- nowcoder search --type must be all or post
- weread-official: type must be one of: ${Object.keys(TYPE_ALI
- weread-official: scope must be one of: ${Object.keys(SEARCH_
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/a9e0afe029a76c91.
Report an issue: GitHub.