jackwener/OpenCLI · error · CommandExecutionError

Unexpected result from reddit whoami: ${JSON.stringify(resul

Error message

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

What it means

This CommandExecutionError is the fallback branch of the reddit whoami result handling: it fires when the result object's kind is none of 'auth', 'http', 'exception', or 'ok' (including kind === undefined when result itself is null/undefined). The CLI stringifies the whole result into the message so developers can see the unexpected shape. It is a defensive invariant check signaling that the whoami wrapper returned something outside its documented result contract.

Source

Thrown at clis/reddit/whoami.js:55

          return { kind: 'auth', detail: 'Not logged in to reddit.com (no identity in /api/me.json)' };
        }
        return { kind: 'ok', identity: me };
      } catch (e) {
        return { kind: 'exception', detail: String(e && e.message || e) };
      }
    })()`);

        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 === 'exception') {
            throw new CommandExecutionError(`whoami failed: ${result.detail}`);
        }
        if (result?.kind !== 'ok') {
            throw new CommandExecutionError(`Unexpected result from reddit whoami: ${JSON.stringify(result)}`);
        }

        const u = result.identity;
        const created = u.created_utc
            ? new Date(u.created_utc * 1000).toISOString().split('T')[0]
            : null;
        const linkKarma = typeof u.link_karma === 'number' ? u.link_karma : null;
        const commentKarma = typeof u.comment_karma === 'number' ? u.comment_karma : null;
        const totalKarma = typeof u.total_karma === 'number'
            ? u.total_karma
            : (linkKarma != null && commentKarma != null ? linkKarma + commentKarma : null);
        const inboxCount = typeof u.inbox_count === 'number' ? u.inbox_count : null;

        return [
            { field: 'Username', value: 'u/' + u.name },
            { field: 'ID', value: u.id ? 't2_' + u.id : null },
            { field: 'Post Karma', value: linkKarma != null ? String(linkKarma) : null },
            { field: 'Comment Karma', value: commentKarma != null ? String(commentKarma) : null },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the JSON.stringify(result) payload in the message to see what shape actually came back.
  2. Re-run the command; a null/undefined result is often a transient page-context race.
  3. Check versions: align the CLI and the embedded whoami snippet/library so both agree on the result contract ({ kind: 'ok'|'auth'|'http'|'exception', ... }).
  4. If result is consistently undefined, verify the automation driver's evaluate() is returning values (not fire-and-forget) and that the page stays open until resolution.
  5. Treat this as a bug if reproducible with a fixed input; file/inspect the wrapper that produces the result object.

Example fix

// before: assuming result always exists
const u = result.identity;

// after (library-side hardening)
if (result?.kind !== 'ok') {
  throw new CommandExecutionError(`Unexpected result: ${JSON.stringify(result)}`);
}
const u = result.identity;
Defensive patterns

Strategy: type-guard

Type guard

function isOkWhoamiResult(result) {
  return !!result && typeof result === 'object' &&
    ['ok', 'auth', 'http', 'exception'].includes(result.kind);
}

Try / catch

try {
  await whoami();
} catch (e) {
  if (e instanceof CommandExecutionError && e.message.startsWith('Unexpected result from reddit whoami:')) {
    const raw = e.message.match(/\{.*\}/s)?.[0];
    console.error('unexpected whoami shape:', raw);
    // retry once on a fresh context, else report as a bug
  } else throw e;
}

Prevention

When it happens

Trigger: The whoami evaluation returns null/undefined, or an object whose kind field is missing or has an unrecognized value (e.g., a partial { kind: undefined, ... } result from a failed or truncated evaluate call).

Common situations: Automation layer returning null because the page closed before the script resolved; an older/newer version of the whoami snippet emitting a result shape this CLI doesn't know; serialization drops the kind field; race conditions where the eval promise resolves with undefined.

Related errors


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