jackwener/OpenCLI · error · CommandExecutionError

Nowcoder whoami failed: ${probe.detail}

Error message

Nowcoder whoami failed: ${probe.detail}

What it means

The WHOAMI_PROBE runs inside the page inside a try/catch; any in-page exception (fetch failure, JSON parse error, script error) is converted to {kind:'exception', detail}. verifyNowcoderIdentity rethrows it as CommandExecutionError 'Nowcoder whoami failed: <detail>'. It indicates the verification script itself failed to execute or reach the API, not an auth rejection.

Source

Thrown at clis/nowcoder/auth.js:48

    if (!d || !d.success || !d.data || !d.data.id) {
      return { kind: 'auth', detail: 'nowcoder profile returned no user data (anonymous)' };
    }
    return { ok: true, user_id: String(d.data.id), nickname: String(d.data.nickname || '') };
  } catch (e) {
    return { kind: 'exception', detail: String(e && e.message || e) };
  }
})()`;

async function verifyNowcoderIdentity(page) {
  if (!await hasNowcoderSessionCookie(page)) {
    throw new AuthRequiredError('nowcoder.com', 'Nowcoder t cookie missing (anonymous)');
  }
  await page.goto('https://www.nowcoder.com/');
  await page.wait(2);
  const probe = await page.evaluate(WHOAMI_PROBE);
  if (probe?.kind === 'auth') throw new AuthRequiredError('nowcoder.com', probe.detail);
  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from nowcoder profile API`);
  if (probe?.kind === 'exception') throw new CommandExecutionError(`Nowcoder whoami failed: ${probe.detail}`);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected nowcoder probe: ${JSON.stringify(probe)}`);
  return { user_id: probe.user_id, nickname: probe.nickname };
}

registerSiteAuthCommands({
  site: 'nowcoder',
  domain: 'nowcoder.com',
  loginUrl: 'https://www.nowcoder.com/login',
  columns: ['user_id', 'nickname'],
  verify: verifyNowcoderIdentity,
  poll: async (page) => {
    if (!await hasNowcoderSessionCookie(page)) {
      throw new AuthRequiredError('nowcoder.com', 'Waiting for Nowcoder login');
    }
    return verifyNowcoderIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the interpolated detail to identify the underlying exception
  2. Re-run after confirming network connectivity to nowcoder.com and gw-c.nowcoder.com
  3. Increase wait time / ensure the homepage fully loads before evaluating
  4. If r.json() got non-JSON, inspect the response content and adapt the probe

Example fix

// before
const who = await verifyNowcoderIdentity(page);
// after
try {
  const who = await verifyNowcoderIdentity(page);
} catch (e) {
  if (/Nowcoder whoami failed: /.test(e.message)) {
    console.error('probe exception, retrying...', e.message);
    await new Promise(r => setTimeout(r, 3000));
    return verifyNowcoderIdentity(page);
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure network reachability and a loaded page before evaluating the probe:
await page.goto('https://www.nowcoder.com/', { waitUntil: 'domcontentloaded' });
await page.wait(2);

Type guard

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

Try / catch

try {
  return await verifyNowcoderIdentity(page);
} catch (e) {
  if (/Nowcoder whoami failed: /.test(e.message)) {
    await new Promise(r => setTimeout(r, 3000));
    return verifyNowcoderIdentity(page); // one retry for transient in-page failures
  }
  throw e;
}

Prevention

When it happens

Trigger: Network failure from the browser to gw-c.nowcoder.com; page.evaluate failing because navigation didn't finish; r.json() throwing on non-JSON (e.g. HTML error page); CSP or extension interference with evaluate.

Common situations: Offline/proxied environments blocking gw-c.nowcoder.com; nowcoder serving an HTML maintenance page; page.wait(2) insufficient on slow loads leaving an incomplete DOM; browser closed mid-command.

Related errors


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