jackwener/OpenCLI · error · ArgumentError

youtube search ${label} must be one of: ${Object.keys(choice

Error message

youtube search ${label} must be one of: ${Object.keys(choices).join(', ')}

What it means

ArgumentError from normalizeChoice validating the --type, --upload, or --sort options for youtube search. The value must be an exact key of the corresponding filter map (type: shorts|video|channel|playlist; upload: hour|today|week|month|year; sort: relevance|date|views|rating). Empty/omitted values are allowed, but any non-empty unknown string throws.

Source

Thrown at clis/youtube/search.js:42

};
const UPLOAD_FILTERS = {
    hour: 'EgIIAQ%3D%3D',
    today: 'EgIIAg%3D%3D',
    week: 'EgIIAw%3D%3D',
    month: 'EgIIBA%3D%3D',
    year: 'EgIIBQ%3D%3D',
};
const SORT_FILTERS = {
    relevance: '',
    date: 'CAI%3D',
    views: 'CAM%3D',
    rating: 'CAE%3D',
};

function normalizeChoice(value, choices, label) {
    const normalized = String(value || '').trim();
    if (normalized && !Object.hasOwn(choices, normalized)) {
        throw new ArgumentError(`youtube search ${label} must be one of: ${Object.keys(choices).join(', ')}`);
    }
    return normalized;
}

function normalizeLimit(value) {
    const limit = Number(value ?? DEFAULT_LIMIT);
    if (!Number.isInteger(limit) || limit <= 0) {
        throw new ArgumentError('youtube search limit must be a positive integer');
    }
    if (limit > MAX_LIMIT) {
        throw new ArgumentError(`youtube search limit must be <= ${MAX_LIMIT}`);
    }
    return limit;
}

cli({
    site: 'youtube',
    name: 'search',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use exactly: type = shorts|video|channel|playlist; upload = hour|today|week|month|year; sort = relevance|date|views|rating
  2. Run `opencli youtube search --help` to see accepted values
  3. Trim/lowercase and map values before passing user-controlled input
  4. Omit the flag entirely instead of passing a guessed value

Example fix

// before
opencli youtube search "lofi" --type films --sort newest
// after
opencli youtube search "lofi" --type video --sort date
Defensive patterns

Strategy: validation

Validate before calling

const TYPE_FILTERS = ['shorts','video','channel','playlist'];
const UPLOAD_FILTERS = ['hour','today','week','month','year'];
const SORT_FILTERS = ['relevance','date','views','rating'];
function validateSearchArgs({ type = '', upload = '', sort = '' } = {}) {
  for (const [label, v, allowed] of [['type',type,TYPE_FILTERS],['upload',upload,UPLOAD_FILTERS],['sort',sort,SORT_FILTERS]]) {
    const n = String(v || '').trim();
    if (n && !allowed.includes(n)) throw new Error(`youtube search ${label} must be one of: ${allowed.join(', ')}`);
  }
}

Type guard

const isSearchFilter = (v, allowed) => typeof v === 'string' && (v.trim() === '' || allowed.includes(v.trim()));

Try / catch

try {
  await run('youtube search', [query, '--type', type]);
} catch (e) {
  if (/must be one of:/.test(e.message)) {
    console.error('Bad filter value:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: `youtube search <query> --type films` (not in TYPE_FILTERS), `--upload yesterday` (valid: hour,today,week,month,year), `--sort newest` (valid: relevance,date,views,rating), including case or whitespace variants like `--type Video`.

Common situations: Guessing filter names instead of reading --help, copying values from YouTube's UI (which differ from the CLI's canonical keys), typos and pluralization, or scripts passing user input unvalidated.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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