jackwener/OpenCLI · error · ArgumentError

upwork ${label} must be >= ${min}

Error message

upwork ${label} must be >= ${min}

What it means

requireBoundedInt validates an integer CLI option and enforces both a minimum and maximum bound. The lower-bound check throws this ArgumentError when the resolved value is below `min`. It guards options like limit/page sizes from values the API or paging logic cannot honor.

Source

Thrown at clis/upwork/utils.js:67

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;
}

/**
 * Upwork job ids are the ciphertext form starting with `~01` or `~02`
 * (the encoded uid surfaced everywhere in URLs and search results).
 * Accepts a bare ciphertext or a full `/jobs/~02…` URL.
 */
export function requireCiphertext(value) {
    let id = String(value ?? '').trim();
    if (!id) throw new ArgumentError('upwork job id is required');
    const urlMatch = id.match(/~0[12]\d+/);
    if (urlMatch) id = urlMatch[0];
    if (!CIPHERTEXT_PATTERN.test(id)) {
        throw new ArgumentError(`upwork job id "${value}" is not a valid ciphertext (expected ~01… or ~02… followed by digits)`);
    }
    return id;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Raise the option value to at least the documented minimum shown in the error message
  2. Omit the option to fall back to the defaultValue passed to requireBoundedInt
  3. Check the command's --help for the valid min/max range for that option

Example fix

// before
$ opencli upwork search "vue" --limit 5
// error: upwork limit must be >= 10
// after
$ opencli upwork search "vue" --limit 10
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(limit);
if (!Number.isInteger(n) || n < min || n > max) throw new RangeError(`limit must be between ${min} and ${max}`);

Type guard

function isBoundedInt(v, min, max) {
  return Number.isInteger(v) && v >= min && v <= max;
}

Try / catch

try {
  await cmd({ limit });
} catch (e) {
  if (e instanceof ArgumentError && /must be >=/.test(e.message)) {
    limit = DEFAULT_LIMIT;
    return cmd({ limit });
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling a command with an option routed through requireBoundedInt (e.g. `limit`) whose value, after requirePositiveInt coercion, is numerically less than the configured min (e.g. limit=0 or a negative number, since 0 and negatives pass requirePositiveInt only if >0 — so realistically limit set below the min bound such as min=10 with limit=5).

Common situations: Passing --limit 0 or a small value like 1 when the command requires a minimum of several results; copy-pasting a limit from another CLI with different bounds; setting limits via config/env with stale small values.

Related errors


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