jackwener/OpenCLI · error · CommandExecutionError

Unexpected result from reddit reply: ${JSON.stringify(result

Error message

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

What it means

A defensive fallthrough error in the reddit `reply` command: thrown when the page-evaluate result's `kind` is none of the recognized values ('ok', 'http', 'reddit-error', 'postcondition', 'exception'). The full result object is JSON-stringified into the message to aid debugging of contract drift between the injected script and the CLI. It almost always indicates a version mismatch or a malformed/unexpected result shape.

Source

Thrown at clis/reddit/reply.js:178

    })()`);

        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 === 'reddit-error') {
            throw new CommandExecutionError(`Reddit rejected reply: ${result.detail}`);
        }
        if (result?.kind === 'postcondition') {
            throw new CommandExecutionError(result.detail);
        }
        if (result?.kind === 'exception') {
            throw new CommandExecutionError(`Reply failed: ${result.detail}`);
        }
        if (result?.kind !== 'ok') {
            throw new CommandExecutionError(`Unexpected result from reddit reply: ${JSON.stringify(result)}`);
        }
        return [{ status: 'success', message: result.detail }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Inspect the JSON payload in the message to see what shape actually came back
  2. Ensure the browser bundle/injected script and CLI code are the same version (reinstall/update the package)
  3. Check the evaluate returned an explicit object with a `kind` field on every code path
  4. File/patch the missing `kind` case in the injected script's result mapping

Example fix

// before
const result = await page.evaluate(scriptThatMayReturnUndefined);
// after
const result = (await page.evaluate(scriptThatMayReturnUndefined)) || { kind: 'exception', detail: 'script returned nothing' };
Defensive patterns

Strategy: type-guard

Type guard

function hasKnownKind(r) {
  return r != null && typeof r === 'object' &&
    ['ok','http','reddit-error','postcondition','exception'].includes(r.kind);
}

Try / catch

try {
  await cli.run('reddit reply', { 'post-id': postId, text });
} catch (e) {
  if (/Unexpected result from reddit reply/.test(e.message)) {
    const payload = JSON.parse(e.message.split(': ').slice(1).join(': '));
    console.error('Unknown result kind:', payload); // report/patch the missing kind
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the reddit reply command when page.evaluate returns an object with an unknown or missing `kind` field — e.g. a newer/older injected script, the evaluate returning undefined/null because the script failed to return, or Reddit serving a page where the script's early return path is skipped.

Common situations: Mixing versions of the CLI and its browser bundle; Reddit serving an unexpected interstitial page so the script returns undefined; editing the injected script and forgetting to update the kind taxonomy.

Related errors


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