jackwener/OpenCLI · error · ArgumentError

tvmaze ${label} cannot be empty

Error message

tvmaze ${label} cannot be empty

What it means

requireString is the TVmaze adapter's input sanitizer: it coerces the value to a string, trims it, and throws ArgumentError if the result is empty. The `label` argument identifies which parameter failed (here invoked for `query`). It guarantees downstream URL building (e.g., encodeURIComponent(query)) never operates on an empty string.

Source

Thrown at clis/tvmaze/utils.js:12

// Shared helpers for the TVmaze adapters.
//
// TVmaze publishes a free, unauthenticated REST API at https://api.tvmaze.com.
// Docs: https://www.tvmaze.com/api
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';

export const TVMAZE_BASE = 'https://api.tvmaze.com';
const UA = 'opencli-tvmaze-adapter (+https://github.com/jackwener/opencli)';

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

export function requireShowId(value) {
    const raw = value;
    const n = typeof raw === 'number' ? raw : Number(String(raw ?? '').trim());
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError(
            'tvmaze show id is required and must be a positive integer',
            'TVmaze show ids appear in the URL: https://www.tvmaze.com/shows/<id>/<slug>.',
        );
    }
    return n;
}

export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
    const raw = value ?? defaultValue;
    const n = typeof raw === 'number' ? raw : Number(raw);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty query string to the command.
  2. If the value comes from a variable or env var, echo it before the call to confirm it is populated.
  3. Add a default or prompt in the calling script when the input is blank.
  4. Catch ArgumentError in wrapper scripts and show a usage message.

Example fix

// before
const query = process.env.SHOW_QUERY;
await tvmazeSearch(query); // SHOW_QUERY unset -> ArgumentError
// after
const query = process.env.SHOW_QUERY;
if (!query || !query.trim()) throw new Error('SHOW_QUERY env var must be set to a show name');
await tvmazeSearch(query);
Defensive patterns

Strategy: validation

Validate before calling

function requireQuery(v) {
    const s = String(v ?? '').trim();
    if (!s) throw new Error('query must be a non-empty string');
    return s;
}

Type guard

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

Try / catch

try {
    const rows = await tvmazeSearch(rawQuery);
} catch (err) {
    if (err instanceof ArgumentError && err.message.includes('cannot be empty')) {
        console.error('Usage: tvmaze search <query> — query must not be empty');
        process.exitCode = 2;
    } else {
        throw err;
    }
}

Prevention

When it happens

Trigger: Calling a TVmaze command (e.g. `query`/search) with an empty, whitespace-only, null, or undefined query argument — e.g. `tvmaze search ''` or a script passing an unset shell variable.

Common situations: Unset environment variables interpolated into the command (`q="$MY_QUERY"` with MY_QUERY empty); a config file with a blank field; piping empty stdin; forgetting to pass the positional argument so it defaults to undefined.

Related errors


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