jackwener/OpenCLI · error · ArgumentError

oeis ${label} cannot be empty

Error message

oeis ${label} cannot be empty

What it means

This ArgumentError is thrown by requireString in clis/oeis/utils.js when a labeled string argument is empty or only whitespace after String() coercion and trimming. It guards OEIS command inputs (e.g. the search query) so an empty request never hits the OEIS API.

Source

Thrown at clis/oeis/utils.js:16

// Shared helpers for the OEIS adapter (Online Encyclopedia of Integer Sequences).
//
// OEIS exposes a single search endpoint that handles both keyword search and
// id lookup via `q=id:Annnnnn`. JSON output via `fmt=json`. No API key.
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';

export const OEIS_BASE = 'https://oeis.org';
const UA = 'opencli-oeis-adapter/1.0 (+https://github.com/jackwener/opencli; mailto:opencli@example.com)';

// OEIS ids are A followed by 6 zero-padded digits (older entries use 6 by convention,
// modern entries can be longer; OEIS itself accepts any digits after A).
const SEQUENCE_ID_PATTERN = /^A\d{1,7}$/;

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

export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
    const raw = value ?? defaultValue;
    const n = typeof raw === 'number' ? raw : Number(raw);
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError(`oeis ${label} must be a positive integer`);
    }
    if (n > maxValue) {
        throw new ArgumentError(`oeis ${label} must be <= ${maxValue}`);
    }
    return n;
}

export function requireSequenceId(value) {
    const raw = String(value ?? '').trim().toUpperCase();
    if (!raw) throw new ArgumentError('oeis sequence id is required (e.g. "A000045" for Fibonacci)');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Supply a non-empty query/id argument to the command.
  2. Check that any shell variable feeding the argument is set and non-empty ("${VAR:?}").
  3. Trim and validate user input before invoking the command.
  4. If the upstream value can be legitimately absent, handle that before calling rather than passing it through.

Example fix

// before (VAR empty)
oeis search "$QUERY"
// after
oeis search "${QUERY:?QUERY must not be empty}"
Defensive patterns

Strategy: validation

Validate before calling

const q = String(raw ?? '').trim();
if (!q) throw new Error('oeis query must be a non-empty string');

Type guard

const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;

Try / catch

try { return await oeisSearch(raw); } catch (e) { if (e instanceof ArgumentError && /cannot be empty/.test(e.message)) { console.error('Provide a non-empty query'); process.exitCode = 2; return; } throw e; }

Prevention

When it happens

Trigger: Calling the oeis search command with a missing, empty (""), or whitespace-only id/query value — e.g. `oeis search ""` or args.id being undefined when requireString(value, 'query') is invoked from query().

Common situations: Shell variable interpolation producing an empty string (unset env var), quoting mistakes that pass an empty argument, scripted calls where a prior step yielded nothing, or forgetting the positional argument entirely.

Related errors


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