jackwener/OpenCLI · error · CommandExecutionError

WeChat Channels whoami failed: ${probe.detail}

Error message

WeChat Channels whoami failed: ${probe.detail}

What it means

The probe's in-page async function caught an unexpected exception (kind:'exception') — e.g. fetch rejected, JSON parsing failed, or page context issues — and rethrows the detail wrapped in this CommandExecutionError. It means the whoami check could not complete, not necessarily that auth failed.

Source

Thrown at clis/wechat-channels/auth.js:44

      if (!r.ok) return { kind: 'http', httpStatus: r.status };
      const d = await r.json();
      if (!d || d.base_resp?.ret !== 0) {
        return { kind: 'auth', detail: 'WeChat Channels auth_data base_resp.ret=' + String(d?.base_resp?.ret) };
      }
      const fu = d.data?.finder_user || d.finder_user || {};
      const userId = String(fu.uniq_id || fu.username || '');
      const name = String(fu.nickname || fu.name || '');
      if (!userId && !name) {
        return { kind: 'auth', detail: 'WeChat Channels auth_data 200 but finder_user empty' };
      }
      return { ok: true, user_id: userId, name };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`);
  if (probe?.kind === 'auth') throw new AuthRequiredError('channels.weixin.qq.com', probe.detail);
  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from auth_data`);
  if (probe?.kind === 'exception') throw new CommandExecutionError(`WeChat Channels whoami failed: ${probe.detail}`);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected WeChat Channels probe: ${JSON.stringify(probe)}`);
  return { user_id: probe.user_id, name: probe.name };
}

registerSiteAuthCommands({
  site: 'wechat-channels',
  domain: 'channels.weixin.qq.com',
  loginUrl: 'https://channels.weixin.qq.com/login.html?from=assistant',
  columns: ['user_id', 'name'],
  quickCheck: hasWechatChannelsSessionCookie,
  verify: verifyWechatChannelsIdentity,
  poll: async (page) => {
    if (!await hasWechatChannelsSessionCookie(page)) {
      throw new AuthRequiredError('channels.weixin.qq.com', 'Waiting for WeChat Channels sessionid cookie');
    }
    return verifyWechatChannelsIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the detail string to see the underlying exception (e.g. 'Failed to fetch' vs JSON parse error).
  2. Simply retry — transient network/page-load races often succeed on a second run.
  3. Increase stability: ensure the page fully loads before verify (the fixed page.wait(2) may be too short on slow networks).
  4. Re-login if the platform keeps redirecting during the probe.
  5. Check for proxies/extensions altering responses to non-JSON.

Example fix

// before (probe raced navigation)
await page.goto(url); await page.wait(2); const probe = await page.evaluate(...);
// after
await page.goto(url, { waitUntil: 'networkidle' });
const probe = await page.evaluate(...);
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure page is settled before probing
await page.goto('https://channels.weixin.qq.com/platform');
await page.wait(5); // longer than default 2s on slow networks

Type guard

function isExceptionProbe(p) { return p != null && p.kind === 'exception' && typeof p.detail === 'string'; }

Try / catch

try {
  await verifyWechatChannelsIdentity(page);
} catch (e) {
  if (/whoami failed/.test(e.message)) {
    await sleep(3000);
    return verifyWechatChannelsIdentity(page); // transient races often clear
  }
  throw e;
}

Prevention

When it happens

Trigger: fetch to auth_data rejects (network interruption, CORS, page navigating mid-probe); r.json() throws on a non-JSON response (error page/HTML); the page was redirected or closed during the 2s post-goto wait so the evaluate context is wrong.

Common situations: Flaky network or proxy injecting HTML error pages; the platform redirecting mid-probe; page navigation/refresh racing the evaluate; browser automation context destroyed.

Related errors


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