jackwener/OpenCLI · error · ArgumentError
boss ${name} cannot be empty
Error message
boss ${name} cannot be empty What it means
readRequiredString normalizes a raw option with String(raw ?? '').trim() and throws ArgumentError when the result is empty. It guards required identifiers (uid, jobId) so the library never builds API URLs with blank IDs. A missing, empty-string, or whitespace-only value triggers it.
Source
Thrown at clis/boss/utils.js:33
*/
export function requirePage(page) {
if (!page)
throw new CommandExecutionError('Browser page required');
}
export function readPositiveInteger(raw, name, fallback, max) {
const value = raw === undefined || raw === null || raw === '' ? fallback : Number(raw);
if (!Number.isInteger(value) || value < 1) {
throw new ArgumentError(`boss ${name} must be a positive integer`);
}
if (max !== undefined && value > max) {
throw new ArgumentError(`boss ${name} must be <= ${max}`);
}
return value;
}
export function readRequiredString(raw, name) {
const value = String(raw ?? '').trim();
if (!value) {
throw new ArgumentError(`boss ${name} cannot be empty`);
}
return value;
}
/**
* Navigate to BOSS chat page and wait for it to settle.
* This establishes the cookie context needed for subsequent API calls.
*/
export async function navigateToChat(page, waitSeconds = 2) {
await page.goto(CHAT_URL);
await page.wait({ time: waitSeconds });
}
/**
* Navigate to a custom BOSS page (for search/detail that use different pages).
*/
export async function navigateTo(page, url, waitSeconds = 1) {
await page.goto(url);
await page.wait({ time: waitSeconds });
}View on GitHub (pinned to 49907e53dc)
Solutions
- Supply the required --uid / --jobId value on the command line.
- Check that the shell variable feeding the flag is actually set and non-blank.
- Verify option parsing (e.g. commander/yargs config) marks the option required so it fails earlier with a clearer message.
Example fix
// before cli friend-detail --uid "$UID" // after UID=abc123 cli friend-detail --uid "$UID" # or guard: [ -n "$UID" ] || exit 1
Defensive patterns
Strategy: validation
Validate before calling
function assertRequiredString(raw, name) {
const v = String(raw ?? '').trim();
if (!v) throw new Error(`${name} cannot be empty`);
return v;
}
assertRequiredString(process.env.BOSS_UID, 'uid'); Type guard
function isNonEmptyString(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await cli.friendDetail({ uid });
} catch (e) {
if (e instanceof ArgumentError && /cannot be empty/.test(e.message)) {
console.error(`Missing required ${e.message.match(/boss (\w+)/)?.[1]}; pass it explicitly.`);
process.exitCode = 2;
return;
}
throw e;
} Prevention
- Mark required options required in your CLI parser so it fails with usage help
- Validate shell variables are non-blank before interpolating into flags
- Trim user-supplied ids before passing them
When it happens
Trigger: Running a command that requires --uid or --jobId but omitting the flag, passing --uid "" or --uid " ", or passing a value that is undefined/null after option parsing.
Common situations: Forgetting the flag in a script; an upstream variable that is empty or unset interpolated into the CLI invocation; shell quoting producing an empty argument (e.g. --uid "$UNSET_VAR").
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
- symbol is required
- 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}
- <username> is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/be65257827d27265.
Report an issue: GitHub.