jackwener/OpenCLI · error · CommandExecutionError

unexpected evaluate envelope: ${JSON.stringify(r)}

Error message

unexpected evaluate envelope: ${JSON.stringify(r)}

What it means

dispatchEvaluateResult's default branch throws CommandExecutionError with `unexpected evaluate envelope: <JSON>`. A null or unrecognized envelope indicates contract drift between the injected browser snippet and the CLI dispatcher — the snippet returned something outside the documented {kind: ...} protocol (following the 'fail loud' reddit precedent).

Source

Thrown at clis/slock/errors.js:28

//   { kind: 'no-thread', parent }       // handled by caller, never reaches dispatcher
export function dispatchEvaluateResult(r) {
  switch (r && r.kind) {
    case 'ok':
      return r.rows;
    case 'auth':
      throw new AuthRequiredError(SLOCK_DOMAIN, r.detail);
    case 'http':
      throw new CommandExecutionError(`HTTP ${r.status} from ${r.where}`);
    case 'no-server':
      throw new ConfigError(r.detail, 'Run `opencli slock server-use <slug>` to set the active server.');
    case 'unresolvable':
      throw new ArgumentError(r.detail);
    case 'no-thread':
      // caller decides what to do (returns a 0-row hint); should never reach here
      throw new CommandExecutionError(`no-thread should be handled by caller, not dispatcher: ${r.parent}`);
    default:
      // unknown / null envelope = contract drift; fail loud (reddit precedent)
      throw new CommandExecutionError(`unexpected evaluate envelope: ${JSON.stringify(r)}`);
  }
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Rerun the command — transient navigation/CSP interruptions often resolve on retry
  2. Upgrade the CLI so snippet and dispatcher versions match
  3. Inspect the JSON in the message: if it's null, check the browser session/URL loads correctly; if it has an unexpected kind, report the contract drift
Defensive patterns

Strategy: retry

Validate before calling

const envelope = result && typeof result === 'object' && typeof result.kind === 'string' ? result : null;
if (!envelope) throw new Error('evaluate returned no envelope — page may have navigated or script was blocked');

Type guard

const isEnvelope = (r) => r != null && typeof r === 'object' && ['ok','auth','http','no-server','unresolvable','no-thread'].includes(r.kind);

Try / catch

try { return dispatchEvaluateResult(result); } catch (e) { if (/unexpected evaluate envelope/.test(e.message)) { await page.reload(); return retryWithBackoff(task, 2); } throw e; }

Prevention

When it happens

Trigger: page.evaluate returned null/undefined (snippet crashed or was blocked, e.g. CSP, navigation interrupted), or a modified/older snippet returned a shape without a recognized kind field.

Common situations: Browser page navigated mid-evaluate so the result is null; antivirus/extension stripping the injected script; half-updated CLI where snippet and dispatcher versions disagree.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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