jackwener/OpenCLI · error · ArgumentError

symbol is required

Error message

symbol is required

What it means

normalizeSymbol() coerces the --symbol argument to a trimmed uppercase string and throws an ArgumentError if the result is empty. This guards the Barchart greeks command, which cannot build a request without a ticker symbol. It fires for missing, null, or whitespace-only symbol values.

Source

Thrown at clis/barchart/greeks.js:15

/**
 * Barchart options greeks overview — IV, delta, gamma, theta, vega, rho
 * for near-the-money options on a given symbol.
 * Auth: CSRF token from <meta name="csrf-token"> + session cookies.
 */
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';

const DEFAULT_LIMIT = 10;
const MIN_LIMIT = 1;
const MAX_LIMIT = 100;

function normalizeSymbol(value) {
    const symbol = String(value ?? '').trim().toUpperCase();
    if (!symbol) throw new ArgumentError('symbol is required');
    return symbol;
}

function normalizeExpiration(value) {
    const expiration = String(value ?? '').trim();
    if (!expiration) return '';
    if (!/^\d{4}-\d{2}-\d{2}$/.test(expiration)) {
        throw new ArgumentError('--expiration must use YYYY-MM-DD format');
    }
    const parsed = new Date(`${expiration}T00:00:00Z`);
    if (Number.isNaN(parsed.getTime()) || parsed.toISOString().slice(0, 10) !== expiration) {
        throw new ArgumentError('--expiration must be a valid calendar date');
    }
    return expiration;
}

function parseLimit(value) {
    if (value === undefined || value === null || value === '') return DEFAULT_LIMIT;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty ticker, e.g. --symbol AAPL.
  2. Check that any shell variable used for the symbol is actually set and non-blank before invoking the command.
  3. Validate/trim the symbol in your wrapper script before calling the CLI.

Example fix

// before
await greeks({ symbol: process.env.TICKER }); // TICKER may be empty
// after
const symbol = (process.env.TICKER || '').trim();
if (!symbol) throw new Error('TICKER env var must be set to a ticker symbol');
await greeks({ symbol });
Defensive patterns

Strategy: validation

Validate before calling

function requireSymbol(value) {
  const s = String(value ?? '').trim().toUpperCase();
  if (!s) throw new Error('symbol is required');
  return s;
}
// call: requireSymbol(process.env.TICKER)

Type guard

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

Try / catch

try {
  await greeks({ symbol });
} catch (e) {
  if (e.name === 'ArgumentError' && /symbol is required/.test(e.message)) {
    console.error('Usage: greeks --symbol <TICKER>');
    process.exitCode = 2;
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the barchart greeks command/API without --symbol, with --symbol="", or with a value that is only whitespace, or passing null/undefined programmatically to the `symbol` option handler.

Common situations: Forgetting the --symbol flag on the command line; shell variables that expand to empty ($SYMBOL unset); scripts passing an empty ticker after stripping; configuration files with a blank symbol field.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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