jackwener/OpenCLI · error · CommandExecutionError

whoami failed: ${result.detail}

Error message

whoami failed: ${result.detail}

What it means

This CommandExecutionError is thrown when the reddit whoami script's result has kind === 'exception', meaning the in-page/in-process whoami evaluation itself threw an exception; result.detail carries the underlying error message. The CLI re-raises it as 'whoami failed: <detail>' so the original failure detail is preserved in the command error. It indicates a client-side execution failure of the whoami routine, not an HTTP status problem or missing auth.

Source

Thrown at clis/reddit/whoami.js:52

        const d = await res.json();
        const me = d?.data;
        if (!me?.name) {
          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 },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Inspect result.detail (the text after 'whoami failed:') to find the original exception and fix its root cause.
  2. Re-run the command once; transient page/context crashes often resolve on a fresh attempt.
  3. If detail shows a script/TypeError, check whether reddit.com markup changed and update the whoami extraction script.
  4. Update the CLI/automation stack (browser, driver, this library) to versions compatible with the current Reddit DOM.
  5. Catch CommandExecutionError and log the full detail before deciding whether to retry or re-authenticate.

Example fix

// before: treating all failures as auth and retrying login
try { await whoami(); } catch { await login(); }

// after: branch on the failure detail
try {
  await whoami();
} catch (e) {
  if (e instanceof AuthRequiredError) await login();
  else throw e; // 'whoami failed: ...' is not fixable by re-login
}
Defensive patterns

Strategy: try-catch

Type guard

function isWhoamiExceptionError(e) {
  return e instanceof CommandExecutionError && e.message.startsWith('whoami failed: ');
}

Try / catch

try {
  await whoami();
} catch (e) {
  if (isWhoamiExceptionError(e)) {
    console.error('whoami runtime failure:', e.message.slice('whoami failed: '.length));
    // one retry after fresh page/context, then give up
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the reddit whoami command when the embedded evaluation throws: e.g., DOM/page context unavailable, a script error inside the whoami snippet, or an unexpected runtime exception captured by the wrapper and returned as { kind: 'exception', detail }.

Common situations: Browser/page crashed or navigated mid-eval so the script context is gone; site markup changes causing the extraction script to throw a TypeError (reading property of undefined); automation driver version mismatch causing evaluate() to fail; timeouts propagating as exceptions inside the probe.

Related errors


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