jackwener/OpenCLI · error · CommandExecutionError

Unexpected result from reddit read: ${JSON.stringify(result)

Error message

Unexpected result from reddit read: ${JSON.stringify(result)}

What it means

Final safety check in the reddit read handler: after all known envelope kinds are handled, the result must be kind 'ok' with an array of rows. Anything else (unknown kind, ok without rows array) triggers this CommandExecutionError that stringifies the whole envelope for debugging. It means the script returned a shape the host does not understand.

Source

Thrown at clis/reddit/read.js:584

            throw new EmptyResultError(result.detail);
        }
        if (result.kind === 'auth') {
            throw new AuthRequiredError('reddit.com', result.detail);
        }
        if (result.kind === 'http') {
            throw new CommandExecutionError(`HTTP ${result.httpStatus} from ${result.where}`);
        }
        if (result.kind === 'malformed') {
            throw new CommandExecutionError(result.detail);
        }
        if (result.kind === 'parser-drift') {
            throw new CommandExecutionError(result.detail);
        }
        if (result.kind === 'expand-failed') {
            throw new CommandExecutionError(result.detail);
        }
        if (result.kind !== 'ok' || !Array.isArray(result.rows)) {
            throw new CommandExecutionError(`Unexpected result from reddit read: ${JSON.stringify(result)}`);
        }
        return result.rows;
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the JSON in the message to see the actual result and its kind.
  2. Reinstall/upgrade the library so the page script and host handler versions match.
  3. If kind is 'ok' with missing rows, report a bug — the script's success path is returning a non-array.
Defensive patterns

Strategy: try-catch

Type guard

const isOkEnvelope = (r) => r && typeof r === 'object' && r.kind === 'ok' && Array.isArray(r.rows);

Try / catch

try {
  return await redditRead(postId);
} catch (e) {
  if (e instanceof CommandExecutionError && /Unexpected result from reddit read/.test(e.message)) {
    console.error('Envelope contract violated — reinstall/upgrade the library');
    // Log e.message (contains full envelope JSON) for a bug report
  }
  throw e;
}

Prevention

When it happens

Trigger: The in-page script returns a new/unknown envelope kind after a library partial update, or returns kind 'ok' but with rows missing/null due to a script bug.

Common situations: Version mismatch between the injected page script and the host handler after an upgrade; manual edits to the script; corrupted install.

Related errors


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