jackwener/OpenCLI · error · CommandExecutionError

Unexpected Instagram probe: ${JSON.stringify(result)}

Error message

Unexpected Instagram probe: ${JSON.stringify(result)}

What it means

A defensive CommandExecutionError thrown when the whoami probe returns a result that is neither ok, nor one of the known kinds ('auth', 'http', 'exception'), or is null/undefined. The library throws this to catch contract violations — i.e. the page.evaluate returned something unexpected, so the result cannot be interpreted safely. It is a bug-catcher rather than an expected runtime condition.

Source

Thrown at clis/instagram/auth.js:40

      });
      if (r.status === 401 || r.status === 403) {
        return { kind: 'auth', detail: 'Instagram /users/info HTTP ' + r.status };
      }
      if (!r.ok) return { kind: 'http', httpStatus: r.status };
      const d = await r.json();
      const user = d?.user;
      if (!user || !user.pk) {
        return { kind: 'auth', detail: 'Instagram /users/info returned no pk — session likely expired' };
      }
      return { ok: true, user_id: String(user.pk), username: String(user.username || ''), full_name: String(user.full_name || '') };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`);
  if (result?.kind === 'auth') throw new AuthRequiredError('www.instagram.com', result.detail);
  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from Instagram /users/info`);
  if (result?.kind === 'exception') throw new CommandExecutionError(`Instagram whoami failed: ${result.detail}`);
  if (!result?.ok) throw new CommandExecutionError(`Unexpected Instagram probe: ${JSON.stringify(result)}`);
  return { user_id: result.user_id, username: result.username, full_name: result.full_name };
}

registerSiteAuthCommands({
  site: 'instagram',
  domain: 'instagram.com',
  loginUrl: 'https://www.instagram.com/accounts/login/',
  columns: ['user_id', 'username', 'full_name'],
  quickCheck: hasInstagramSessionCookie,
  verify: verifyInstagramIdentity,
  poll: async (page) => {
    if (!await hasInstagramSessionCookie(page)) {
      throw new AuthRequiredError('www.instagram.com', 'Waiting for Instagram sessionid cookie');
    }
    return verifyInstagramIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command — a transient page navigation/context destruction often resolves on retry
  2. Make sure the page stays open on instagram.com until the command finishes (don't close or navigate the browser mid-command)
  3. Ensure CLI and its site-auth helpers are the same version; reinstall/update the CLI if mixed
  4. If reproducible, report it — the probe returned a shape the code does not recognize

Example fix

// before: closing the browser mid-command causes evaluate to yield undefined
// after: await the command before closing
await opencli instagram whoami;
await browser.close();
Defensive patterns

Strategy: type-guard

Validate before calling

null

Type guard

function isKnownProbeResult(r) {
  return r != null && typeof r === 'object' &&
    ['auth', 'http', 'exception'].includes(r.kind) || r?.ok === true;
}
// treat anything failing this guard as the 'Unexpected Instagram probe' case

Try / catch

try {
  await instagramWhoami();
} catch (e) {
  if (e.message.startsWith('Unexpected Instagram probe:')) {
    // evaluate returned null/unknown shape — usually a destroyed page context
    await reopenInstagramPage();
    return instagramWhoami();
  }
  throw e;
}

Prevention

When it happens

Trigger: page.evaluate in verifyInstagramIdentity resolves to null/undefined (page navigation destroyed the execution context, evaluate failed silently) or returns an object with an unrecognized `kind` — e.g. an older probe script or a wrapper that altered the return shape.

Common situations: Page navigated away or was closed while the probe was running; a browser automation layer returning undefined from evaluate; mixing CLI versions where the probe script and the dispatcher disagree; a site-auth wrapper modifying probe results.

Related errors


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