{"record":{"id":"7094ec5df983e935","repo":"jackwener/OpenCLI","slug":"barchart-greeks-returned-an-unreadable-options-pay","errorCode":null,"errorMessage":"Barchart greeks returned an unreadable options payload${data.message ? `: ${data.message}` : ''}","messagePattern":"Barchart greeks returned an unreadable options payload(.+?)` : ''\\}","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/barchart/greeks.js","lineNumber":163,"sourceCode":"                vega: r.vega,\n                rho: r.rho,\n                volume: r.volume,\n                openInterest: r.openInterest,\n                expiration: r.expirationDate,\n              };\n            })\n          };\n        } catch(e) {\n          return { ok: false, reason: 'exception', message: e?.message || String(e) };\n        }\n      })()\n    `));\n        if (!data || data.ok !== true) {\n            if (data?.reason === 'http') {\n                throw new CommandExecutionError(`Barchart greeks request failed: HTTP ${data.status}${data.statusText ? ` ${data.statusText}` : ''}`);\n            }\n            if (data?.reason === 'malformed') {\n                throw new CommandExecutionError(`Barchart greeks returned an unreadable options payload${data.message ? `: ${data.message}` : ''}`);\n            }\n            if (data?.reason === 'exception') {\n                throw new CommandExecutionError(`Barchart greeks request failed: ${data.message || 'unknown error'}`);\n            }\n            throw new CommandExecutionError(`Failed to fetch Barchart greeks for ${symbol}`);\n        }\n        if (!Array.isArray(data.rows)) {\n            throw new CommandExecutionError('Barchart greeks returned an unreadable options payload');\n        }\n        if (data.rows.length === 0) {\n            throw new EmptyResultError('barchart greeks', `No option greeks were returned for ${symbol}. Confirm the symbol, expiration, and Barchart login state.`);\n        }\n        return data.rows.map(r => {\n            if (!r || typeof r !== 'object' || Array.isArray(r)) {\n                throw new CommandExecutionError('Barchart greeks returned a malformed option row');\n            }\n            const type = String(r.type || '').trim();\n            const expirationValue = String(r.expiration || '').trim();","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/barchart/greeks.js#L145-L181","documentation":"When the in-browser evaluation completes but its result cannot be interpreted — data.ok !== true with reason:'malformed' — the CLI throws this CommandExecutionError. The optional data.message appends what specifically was unreadable. It means the response arrived but did not match the expected greeks payload shape.","triggerScenarios":"The browser-context script returned { ok: false, reason: 'malformed', message } because the fetched body was not parseable as the expected options payload — e.g. HTML instead of JSON (login page, bot challenge) or a changed schema.","commonSituations":"Barchart serving an anti-bot/Cloudflare-style interstitial page; being logged out so a login HTML page is returned; Barchart changing the greeks response schema after a site update; truncated responses on flaky connections.","solutions":["Check the appended data.message for what was unreadable, then open the greeks page in a browser to see what is actually returned.","Re-login to Barchart if the page is returning login HTML instead of data.","Complete any CAPTCHA/bot-challenge in the browser session, then retry.","If Barchart changed its payload schema, update the extraction/parsing script to the new shape."],"exampleFix":"// before\nif (!data || data.ok !== true) throw new CommandExecutionError('unreadable payload');\n// after\nif (!data || data.ok !== true) {\n  if (typeof data?.body === 'string' && data.body.includes('Sign In')) {\n    throw new CommandExecutionError('Barchart session expired — got login page');\n  }\n  throw new CommandExecutionError('unreadable payload');\n}","handlingStrategy":"type-guard","validationCode":"// Confirm the page returns data, not a login/interstitial, before parsing\nconst html = await page.content();\nif (/sign in|captcha|access denied/i.test(html)) {\n  throw new Error('Barchart returned an interstitial page — authenticate first');\n}","typeGuard":"function isGreeksEnvelope(v) {\n  return v !== null && typeof v === 'object' &&\n    (v.ok === true ? Array.isArray(v.rows) : ['http', 'malformed', 'exception'].includes(v.reason));\n}","tryCatchPattern":"try {\n  const rows = await greeks({ symbol });\n} catch (e) {\n  if (e.message.includes('unreadable options payload')) {\n    await refreshSession(); // likely got login HTML or a bot challenge\n    return greeks({ symbol });\n  }\n  throw e;\n}","preventionTips":["Keep the automated browser session logged in so data pages load instead of login HTML","Re-verify the payload shape after any Barchart site update","Inspect the appended data.message in the error for the specific parse failure"],"tags":["parsing","scraping","barchart","schema-change"],"backgroundTag":"unexpected-response-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}