jackwener/OpenCLI · error · CommandExecutionError

Unexpected result from reddit subreddit-info: ${JSON.stringi

Error message

Unexpected result from reddit subreddit-info: ${JSON.stringify(result)}

What it means

CommandExecutionError thrown as a defensive fallthrough when the browser-evaluated result has an unrecognized 'kind' (or result itself is null/undefined). All known kinds (missing/http/malformed/exception/ok) are handled above, so this indicates an unexpected runtime contract violation between the page.evaluate payload and the Node handler.

Source

Thrown at clis/reddit/subreddit-info.js:89

      } catch (e) {
        return { kind: 'exception', detail: String(e && e.message || e) };
      }
    })()`);

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

        const s = result.info;
        const created = s.created_utc
            ? new Date(s.created_utc * 1000).toISOString().split('T')[0]
            : null;
        const subscribers = typeof s.subscribers === 'number' ? s.subscribers : null;
        const activeNow = typeof s.active_user_count === 'number'
            ? s.active_user_count
            : (typeof s.accounts_active === 'number' ? s.accounts_active : null);
        const description = typeof s.public_description === 'string'
            ? s.public_description.trim()
            : '';

        return [
            { field: 'Name', value: s.display_name_prefixed || ('r/' + s.display_name) },
            { field: 'Title', value: typeof s.title === 'string' ? s.title : null },
            { field: 'Subscribers', value: subscribers != null ? String(subscribers) : null },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command — a transient page navigation can make evaluate return undefined
  2. Ensure a single consistent version of the library is installed (no mixed patched copies) and reinstall if in doubt
  3. Report the printed JSON.stringify(result) payload in a bug report — it shows exactly what unexpected shape came back
  4. Avoid interfering with the browser window while the command runs so the page is not navigated away mid-evaluation
Defensive patterns

Strategy: try-catch

Validate before calling

// run a smoke invocation first and assert a known kind is returned
const probe = await cli.redditSubredditInfo('python');
if (!probe) throw new Error('evaluate returned undefined; environment broken');

Type guard

function isUnexpectedResultErr(e){ return e instanceof Error && e.message.startsWith('Unexpected result from reddit subreddit-info:'); }

Try / catch

try { await cli.redditSubredditInfo(name); }
catch (e) {
  if (e.message.startsWith('Unexpected result from reddit subreddit-info:')) {
    reportBug(e.message); // message embeds JSON.stringify(result)
    return null;
  }
  throw e;
}

Prevention

When it happens

Trigger: result is undefined or null (evaluate returned nothing, page navigated during evaluation), or a future/unknown kind value appears after a library version mismatch between the browser snippet and the Node-side handler.

Common situations: Page context destroyed mid-evaluate so evaluate resolves undefined; running a mixed/patched version of the library where the browser snippet returns new kinds the Node handler does not know; serialization dropping the object.

Related errors


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