jackwener/OpenCLI · warning · CommandExecutionError

Unexpected nowcoder probe

Error message

Unexpected nowcoder probe: ${JSON.stringify(probe)}

What it means

After checking known probe kinds (auth/http/exception), verifyNowcoderIdentity throws CommandExecutionError 'Unexpected nowcoder probe: <json>' if the probe result is neither {ok:true} nor a recognized kind — e.g. null/undefined probe, a probe missing `ok`, or an unrecognized structure. This is a defensive catch-all indicating the probe contract changed or evaluate returned garbage.

Solutions

  1. Inspect the JSON in the message to see what the probe actually returned
  2. Ensure page.evaluate is executing WHOAMI_PROBE (a fully loaded nowcoder.com page)
  3. Sync WHOAMI_PROBE and verifyNowcoderIdentity so success always includes ok:true, user_id, nickname
  4. Update library/browser if evaluate serialization behavior changed

Example fix

// before
const probe = await page.evaluate(WHOAMI_PROBE);
if (probe?.kind === 'auth') throw new AuthRequiredError('nowcoder.com', probe.detail);
// after
const probe = await page.evaluate(WHOAMI_PROBE);
if (!probe || typeof probe !== 'object') {
  throw new CommandExecutionError(`Unexpected nowcoder probe: ${JSON.stringify(probe)}`);
}
if (probe?.kind === 'auth') throw new AuthRequiredError('nowcoder.com', probe.detail);
Defensive patterns

Strategy: type-guard

Validate before calling

const probe = await page.evaluate(WHOAMI_PROBE);
if (!probe || typeof probe !== 'object') {
  throw new CommandExecutionError(`Unexpected nowcoder probe: ${JSON.stringify(probe)}`);
}

Type guard

function isValidProbe(p) {
  return !!p && typeof p === 'object' &&
    (p.ok === true || ['auth','http','exception'].includes(p.kind));
}

Try / catch

try {
  return await verifyNowcoderIdentity(page);
} catch (e) {
  if (/Unexpected nowcoder probe: null|undefined/.test(e.message)) {
    // evaluate returned nothing — reload page and retry
    await page.goto('https://www.nowcoder.com/');
    return verifyNowcoderIdentity(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: page.evaluate returning null (script failed to return), an older browser serializing differently, WHOAMI_PROBE edited so the success path lost {ok:true}, or navigation to an error page returning an unexpected object.

Common situations: Library version mismatch between probe script and verifier; headless browser quirks returning undefined from evaluate; DOM so broken the probe returned a shape the verifier doesn't know.

Related errors


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

Appendix: source

Thrown at clis/nowcoder/auth.js:49

      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)