jackwener/OpenCLI · warning · ArgumentError
${label} cannot be empty
Error message
${label} cannot be empty What it means
resolveOptionalFilePath treats a provided path argument as optional: undefined/null/empty string returns ''. But if a non-empty raw value is given whose trimmed form is empty (e.g. whitespace-only), it throws ArgumentError with the parameter's label. This catches shell quoting accidents where a flag was passed but the value collapsed to whitespace.
Source
Thrown at clis/twitter/archive.js:14
import fs from 'node:fs';
import path from 'node:path';
import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
// Safety cap only. Full-archive runs can set a higher page budget via --max-pages.
export const DEFAULT_MAX_PAGINATION_PAGES = 100;
const HARD_MAX_PAGINATION_PAGES = 100000;
export function resolveOptionalFilePath(raw, label) {
if (raw === undefined || raw === null || raw === '')
return '';
const value = String(raw).trim();
if (!value)
throw new ArgumentError(`${label} cannot be empty`);
return path.resolve(value);
}
export function ensureParentDir(filePath) {
if (!filePath)
return;
fs.mkdirSync(path.dirname(filePath), { recursive: true });
}
function removeFile(filePath) {
if (!filePath)
return;
try {
fs.rmSync(filePath, { force: true });
}
catch {
}
}View on GitHub (pinned to 49907e53dc)
Solutions
- Check the value passed to --resume-file/--output-file is a real non-blank path
- In shell, quote variables and guard: ${OUTPUT_FILE:?unset}
- Omit the flag entirely if you do not want a file — the helper returns '' for absent values
- echo the constructed command line to see what the flag actually received
Example fix
// before
node cli.js twitter archive --resume-file "$RESUME_FILE"
// after
node cli.js twitter archive ${RESUME_FILE:+--resume-file "$RESUME_FILE"} Defensive patterns
Strategy: validation
Validate before calling
function safePathArg(v) {
if (v === undefined || v === null) return '';
const s = String(v).trim();
return s || null; // null signals 'flag passed but blank — fix before calling'
} Type guard
function isNonEmptyPath(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
try {
await archiveCmd(kwargs);
} catch (err) {
if (err instanceof ArgumentError && err.message.includes('cannot be empty')) {
console.error('A path flag was passed with a blank value — check shell variables');
} else throw err;
} Prevention
- Use ${VAR:?unset} in shell to fail early on blank variables
- Omit optional flags entirely instead of passing empty values
- Echo the assembled command before running in scripts
- Trim and validate path args at script boundaries
When it happens
Trigger: Passing --resume-file or --output-file with a value that is only whitespace after String(raw).trim() — e.g. --output-file " " or an unquoted shell variable that expands to spaces.
Common situations: Unset environment variables quoted in shell ($OUTPUT_FILE expanding to ''), copy-paste artifacts, or scripts building CLI args with empty variables.
Related errors
- ${label} is required
- ${label} must be a positive integer
- ${label} must be <= ${maxValue}
- dblp ${label} must be a positive integer
- dblp ${label} must be <= ${maxValue}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/a4146e4fb6cf241c.
Report an issue: GitHub.