jackwener/OpenCLI · error · CommandExecutionError

WeRead whoami failed: ${result.detail}

Error message

WeRead whoami failed: ${result.detail}

What it means

verifyWereadIdentity in clis/weread/auth.js throws CommandExecutionError when the in-page probe throws a JS exception — the evaluate body catches it and returns {kind:'exception', detail}, and the library re-raises it as `WeRead whoami failed: <detail>`. The identity probe never completed, so the failure is client-side inside the page context.

Source

Thrown at clis/weread/auth.js:41

        return { kind: 'auth', detail: 'WeRead /web/user HTTP ' + res.status };
      }
      if (!res.ok) return { kind: 'http', httpStatus: res.status };
      const d = await res.json();
      if (d && d.errCode && d.errCode !== 0) {
        return { kind: 'auth', detail: 'WeRead /web/user errCode=' + d.errCode };
      }
      return {
        ok: true,
        user_id: String(d.userVid || wrVid),
        name: String(d.name || d.nickName || ''),
      };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`);
  if (result?.kind === 'auth') throw new AuthRequiredError('weread.qq.com', result.detail);
  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /web/user`);
  if (result?.kind === 'exception') throw new CommandExecutionError(`WeRead whoami failed: ${result.detail}`);
  if (!result?.ok) throw new CommandExecutionError(`Unexpected WeRead probe: ${JSON.stringify(result)}`);
  return { user_id: result.user_id, name: result.name };
}

registerSiteAuthCommands({
  site: 'weread',
  domain: 'weread.qq.com',
  loginUrl: 'https://weread.qq.com/',
  columns: ['user_id', 'name'],
  quickCheck: hasWereadSessionCookie,
  verify: verifyWereadIdentity,
  poll: async (page) => {
    if (!await hasWereadSessionCookie(page)) {
      throw new AuthRequiredError('weread.qq.com', 'Waiting for WeRead wr_vid cookie');
    }
    return verifyWereadIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the detail suffix for the underlying exception (e.g. 'Failed to fetch' vs 'Unexpected token < in JSON').
  2. Re-run the command — 'Failed to fetch' is often a transient network/navigation issue.
  3. If the JSON parse fails, WeRead returned non-JSON — clear cookies and re-login at weread.qq.com.
  4. Ensure the attached Chrome page stays open and is not redirected during verification; update Chrome if fetch is unavailable.

Example fix

// before
CommandExecutionError: WeRead whoami failed: Failed to fetch
// after: keep weread.qq.com tab open/stable and retry, or re-login:
$ opencli weread login && opencli weread whoami
Defensive patterns

Strategy: retry

Try / catch

try { return await verifyWereadIdentity(page); } catch (e) {
  if (/WeRead whoami failed/.test(e.message)) {
    console.error('In-page probe threw:', e.message, '— keep the weread.qq.com tab open and retry.');
  } else throw e;
}

Prevention

When it happens

Trigger: Inside page.evaluate, document.cookie access, fetch('/web/user'), or res.json() throws — e.g. TypeError 'fetch is not defined' on older pages, network error, JSON parse failure of a non-JSON body, or CSP blocking the fetch.

Common situations: Browser page navigated away or closed mid-probe; page context lacking fetch; /web/user returning HTML that breaks res.json(); extension or CSP interfering; Chrome automation page detached.

Related errors


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