jackwener/OpenCLI · error · ArgumentError

upwork ${label} cannot be empty

Error message

upwork ${label} cannot be empty

What it means

An ArgumentError thrown by requireQuery when the supplied query value is empty or whitespace-only after trimming. Every upwork subcommand that needs a search term funnels through this guard so the CLI never issues a query with a blank search string.

Source

Thrown at clis/upwork/utils.js:52

    if (value && typeof value === 'object' && !Array.isArray(value) && 'session' in value && 'data' in value) {
        return value.data;
    }
    return value;
}

export function isPlainObject(value) {
    return value !== null && typeof value === 'object' && !Array.isArray(value);
}

function coerceInt(value) {
    if (value === undefined || value === null || value === '') return NaN;
    const n = typeof value === 'number' ? value : Number(value);
    return Number.isFinite(n) && Number.isInteger(n) ? n : NaN;
}

export function requireQuery(value, label = 'query') {
    const q = String(value ?? '').trim();
    if (!q) throw new ArgumentError(`upwork ${label} cannot be empty`);
    return q;
}

export function requirePositiveInt(value, defaultValue, label) {
    const raw = value ?? defaultValue;
    const n = coerceInt(raw);
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError(`upwork ${label} must be a positive integer`);
    }
    return n;
}

export function requireBoundedInt(value, defaultValue, min, max, label) {
    const n = requirePositiveInt(value, defaultValue, label);
    if (n < min) throw new ArgumentError(`upwork ${label} must be >= ${min}`);
    if (n > max) throw new ArgumentError(`upwork ${label} must be <= ${max}`);
    return n;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty query string to the command.
  2. If the query comes from a variable or file, check it is populated before invoking (e.g. [ -n "$QUERY" ] || exit 1).
  3. Trim user input yourself and re-prompt if it is blank.
  4. Review the command's argument order in case the query positional was skipped.

Example fix

// before
await cli.search(process.env.QUERY) // QUERY is unset -> ArgumentError
// after
const q = (process.env.QUERY || '').trim();
if (!q) throw new Error('QUERY env var is required');
await cli.search(q)
Defensive patterns

Strategy: validation

Validate before calling

function requireQuery(value, label = 'query') {
  const q = String(value ?? '').trim();
  if (!q) throw new ArgumentError(`upwork ${label} cannot be empty`);
  return q;
}
// run before the call:
if (!String(rawQuery ?? '').trim()) throw new Error('Provide a non-empty search query');

Type guard

function isNonEmptyQuery(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  rows = await cli.search(query);
} catch (e) {
  if (e.name === 'ArgumentError' && String(e.message).includes('cannot be empty')) {
    console.error('Usage: upwork search <query>');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling an upwork command with an empty string, only-whitespace string, null, or undefined for the query argument - e.g. query: '' or the shell variable holding the query being unset.

Common situations: An unset/empty shell variable interpolated into the command; reading the query from config or a file that came back empty; forgetting to pass the positional argument; a script piping an empty line as the query.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/a947d1702086ce61. Report an issue: GitHub.