jackwener/OpenCLI · error · CommandExecutionError

Qwen whoami failed: ${result.detail}

Error message

Qwen whoami failed: ${result.detail}

What it means

verifyQwenIdentity runs an inline browser-side whoami probe against Qwen's /api/v1/auths/ endpoint. If the probe script itself throws (network crash, page closed, CSP, JS error inside the probe), it returns {kind:'exception'} and this CommandExecutionError surfaces the raw exception message. It means the identity check could not be completed, not that the user is logged out (that path throws AuthRequiredError instead).

Source

Thrown at clis/qwen/auth.js:38

    try {
      const token = ${JSON.stringify(token)};
      const res = await fetch('/api/v1/auths/', { credentials: 'include', headers: { 'Authorization': 'Bearer ' + token, 'Accept': 'application/json' } });
      if (res.status === 401 || res.status === 403) {
        return { kind: 'auth', detail: 'Qwen /api/v1/auths/ HTTP ' + res.status };
      }
      if (!res.ok) return { kind: 'http', httpStatus: res.status };
      const d = await res.json();
      if (!d || !d.id) {
        return { kind: 'auth', detail: 'Qwen /api/v1/auths/ returned no user id' };
      }
      return { ok: true, user_id: String(d.id), name: String(d.name || '') };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`);
  if (result?.kind === 'auth') throw new AuthRequiredError('qwen.ai', result.detail);
  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/v1/auths/`);
  if (result?.kind === 'exception') throw new CommandExecutionError(`Qwen whoami failed: ${result.detail}`);
  if (!result?.ok) throw new CommandExecutionError(`Unexpected Qwen probe: ${JSON.stringify(result)}`);
  return { user_id: result.user_id, name: result.name };
}

registerSiteAuthCommands({
  site: 'qwen',
  domain: 'qwen.ai',
  loginUrl: 'https://chat.qwen.ai/auth?action=login',
  columns: ['user_id', 'name'],
  quickCheck: hasQwenSessionCookie,
  verify: verifyQwenIdentity,
  poll: async (page) => {
    if (!await hasQwenSessionCookie(page)) {
      throw new AuthRequiredError('qwen.ai', 'Waiting for Qwen token cookie');
    }
    return verifyQwenIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read result.detail in the message and fix the underlying exception it names (DNS, proxy, TLS, page closed).
  2. Re-run the command with network access to qwen.ai ensured; disable VPN/proxy or set proxy env vars.
  3. Re-login via `qwen auth login` to restore a fresh page/context, then retry whoami.
  4. Update the CLI; if Qwen changed its frontend, the inline probe may need a newer version.

Example fix

// before
const result = await page.evaluate(probeScript); // throws -> kind:'exception'
// after
try {
  const result = await page.evaluate(probeScript);
} catch (e) {
  return { kind: 'exception', detail: String(e && e.message || e) }; // detail now tells you the real cause
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before calling
const ok = typeof navigator !== 'undefined' || (page && !page.isClosed?.());
if (!ok) throw new Error('Browser page unavailable for Qwen probe');

Type guard

function isProbeResult(r) {
  return r !== null && typeof r === 'object' &&
    (r.kind === 'auth' || r.kind === 'http' || r.kind === 'exception' || r.ok === true);
}

Try / catch

try {
  const user = await verifyQwenIdentity(page);
} catch (e) {
  if (String(e.message).startsWith('Qwen whoami failed:')) {
    // inspect detail after the prefix; check network/proxy, restart browser, retry once
  } else throw e;
}

Prevention

When it happens

Trigger: The inline node/browser probe passed to an execution helper throws any exception; verifyQwenIdentity catches it, packages it as result.kind='exception' with detail=String(e.message||e), and the check at clis/qwen/auth.js:38 rethrows it as `Qwen whoami failed: <detail>`.

Common situations: Browser context crashed or page navigated mid-probe; fetch to qwen.ai blocked by network/VPN/proxy or CORS; TLS interception; Qwen frontend changed so the probe script references a missing global; running headless without the Qwen page loaded.

Related errors


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