jackwener/OpenCLI · error · ArgumentError
${label} is required
Error message
${label} is required What it means
normalizeRequiredString normalizes a required text option (bookTarget/query) via normalizeSearchText and throws ArgumentError when the normalized result is empty. It means a mandatory input was missing, null, or whitespace-only after trimming.
Source
Thrown at clis/weread/book-search.js:54
function parseOptionalFiniteNumber(value) {
if (value == null || value === '')
return null;
const n = Number(value);
return Number.isFinite(n) ? n : null;
}
function parseHasMore(value) {
if (value === true || value === 1 || value === '1')
return true;
if (value === false || value === 0 || value === '0')
return false;
return null;
}
function normalizeRequiredString(value, label) {
const text = normalizeSearchText(value);
if (!text) {
throw new ArgumentError(`${label} is required`);
}
return text;
}
function parseWereadReaderUrl(value) {
let url;
try {
url = new URL(String(value || ''), WEREAD_WEB_ORIGIN);
}
catch {
return '';
}
const pathParts = url.pathname.split('/').filter(Boolean);
if (url.protocol !== 'https:' || url.hostname !== 'weread.qq.com' || pathParts[0] !== 'web' || pathParts[1] !== 'reader' || !pathParts[2]) {
return '';
}
if (pathParts.length !== 3) {
return '';View on GitHub (pinned to 49907e53dc)
Solutions
- Provide a non-empty value for the labeled argument
- Check for unset shell variables: use "${QUERY:?QUERY is required}" before invoking
- Trim is not enough — pass real search text, not whitespace
- Add an early check in your wrapper script before calling the CLI
Example fix
// before QUERY="" weread book-search --query "$QUERY" // after QUERY="zen and the art" weread book-search --query "$QUERY"
Defensive patterns
Strategy: validation
Validate before calling
const query = (process.env.QUERY ?? '').trim();
if (!query) {
console.error('QUERY is required and must be non-empty');
process.exit(2);
} Type guard
const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;
Try / catch
try {
await runCommand(['book-search', '--query', query]);
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('is required')) {
console.error('Missing required argument: ' + e.message); process.exitCode = 2;
} else throw e;
} Prevention
- Use ${VAR:?message} shell expansion to fail fast on unset variables
- Trim and check inputs in wrapper scripts before delegating to the CLI
- Never forward optional flags as empty strings; omit them instead
When it happens
Trigger: Running the command without the required --query (or book target) argument, or passing '' or ' ' — normalizeSearchText strips whitespace and falsy/empty results throw.
Common situations: Shell variables are unset or empty ($QUERY expands to nothing), quoting drops the argument, scripts forward an optional flag as an empty string, or users forget the positional argument.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- INVALID_ARGUMENT
- INVALID_ARGUMENT
- Collection name cannot be empty
- ${label} must be a positive integer
- ${label} must be an integer >= ${min}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d3b7c00b6d746684.
Report an issue: GitHub.