jackwener/OpenCLI · error · CommandExecutionError

Failed to fetch Barchart greeks for

Error message

Failed to fetch Barchart greeks for ${symbol}

What it means

This fallback CommandExecutionError is thrown when the greeks envelope reports ok !== true but none of the known reasons ('http', 'malformed', 'exception') matched — an unexpected envelope shape. The requested symbol is interpolated into the message to aid debugging. It indicates an unrecognized failure mode from the browser evaluation layer.

Solutions

  1. Run the command with verbose/debug output if available to inspect the raw browser-evaluation return value.
  2. Re-run the command once — transient navigation/timing issues often produce undefined returns.
  3. Verify the browser session and page load: open the greeks page manually to confirm it loads for your session.
  4. If you modified the evaluation script, restore its return path so it always resolves to { ok: true, rows } or a { ok:false, reason } envelope.

Example fix

// before
return; // early return yields undefined -> 'Failed to fetch ...'
// after
return { ok: false, reason: 'malformed', message: 'no rows container found' };
Defensive patterns

Strategy: fallback

Validate before calling

// Ensure the evaluation layer always returns a recognized envelope
const raw = await browserEval(script);
if (raw === undefined || raw === null) {
  console.warn('Browser evaluation returned nothing — page may have navigated away');
}

Type guard

function hasKnownReason(v) {
  return v !== null && typeof v === 'object' && typeof v.ok === 'boolean' &&
    (v.ok || ['http', 'malformed', 'exception'].includes(v.reason));
}

Try / catch

async function safeGreeks(symbol) {
  try {
    return await greeks({ symbol });
  } catch (e) {
    if (e.message.startsWith('Failed to fetch Barchart greeks')) {
      await new Promise(r => setTimeout(r, 3000));
      return greeks({ symbol }); // one retry; transient undefined returns are common
    }
    throw e;
  }
}

Prevention

When it happens

Trigger: The browser evaluation returned a falsy value (data undefined/null) or an object with ok !== true and no recognized reason field — e.g. the script's returned expression evaluated to undefined because the IIFE returned nothing, or unwrapBrowserResult got an unexpected shape.

Common situations: Browser context returning undefined after a silent script failure or page navigation; a version mismatch where the wrapper script no longer emits the expected {ok, reason} envelope; premature page close discarding the return value; editing the in-page script so its return path was dropped.

Related errors


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

Appendix: source

Thrown at clis/barchart/greeks.js:168

              };
            })
          };
        } catch(e) {
          return { ok: false, reason: 'exception', message: e?.message || String(e) };
        }
      })()
    `));
        if (!data || data.ok !== true) {
            if (data?.reason === 'http') {
                throw new CommandExecutionError(`Barchart greeks request failed: HTTP ${data.status}${data.statusText ? ` ${data.statusText}` : ''}`);
            }
            if (data?.reason === 'malformed') {
                throw new CommandExecutionError(`Barchart greeks returned an unreadable options payload${data.message ? `: ${data.message}` : ''}`);
            }
            if (data?.reason === 'exception') {
                throw new CommandExecutionError(`Barchart greeks request failed: ${data.message || 'unknown error'}`);
            }
            throw new CommandExecutionError(`Failed to fetch Barchart greeks for ${symbol}`);
        }
        if (!Array.isArray(data.rows)) {
            throw new CommandExecutionError('Barchart greeks returned an unreadable options payload');
        }
        if (data.rows.length === 0) {
            throw new EmptyResultError('barchart greeks', `No option greeks were returned for ${symbol}. Confirm the symbol, expiration, and Barchart login state.`);
        }
        return data.rows.map(r => {
            if (!r || typeof r !== 'object' || Array.isArray(r)) {
                throw new CommandExecutionError('Barchart greeks returned a malformed option row');
            }
            const type = String(r.type || '').trim();
            const expirationValue = String(r.expiration || '').trim();
            if (!/^(call|put)$/i.test(type) || r.strike === undefined || r.strike === null || r.strike === '' || !expirationValue) {
                throw new CommandExecutionError('Barchart greeks returned a malformed option row identity');
            }
            return {
                type,

View on GitHub (pinned to 49907e53dc)