jackwener/OpenCLI · error

${label}

Error message

${label}

What it means

Inside the in-page resolver script from buildResolveInstagramUserIdJs, normalizeInstagramUserId validates that a value is a numeric-string id. If it is not (empty, undefined, or non-numeric), it throws new Error(label) — so the thrown message IS the caller's label, e.g. 'Instagram web_profile_info returned no valid user id for: someuser'. It means Instagram's response did not contain a usable numeric user id at the expected path (data.user.id or user.pk).

Source

Thrown at clis/instagram/_shared/user-id.js:13

/**
 * In-page snippet that resolves `username` to a numeric user id in `userId`.
 *
 * `web_profile_info` answers HTTP 400 for business and professional accounts,
 * so the commands that need an id fall back to feed-by-username. Its root
 * `user.pk` is the profile owner; `items[0].user.pk` can be a pinned collab
 * author. Callers must already have `username` and `opts` in scope.
 */
export function buildResolveInstagramUserIdJs() {
    return `
  function normalizeInstagramUserId(value, label) {
    const id = typeof value === 'number' ? String(value) : (typeof value === 'string' ? value.trim() : '');
    if (!/^\\d+$/.test(id)) throw new Error(label);
    return id;
  }
  async function readInstagramJson(response, label) {
    try {
      return await response.json();
    } catch {
      throw new Error(label + ' returned invalid JSON');
    }
  }
  function throwInstagramHttpError(response, label, username) {
    if (response.status === 404) throw new Error('User not found: ' + username);
    if (response.status === 401 || response.status === 403) {
      throw new Error('HTTP ' + response.status + ' - make sure you are logged in to Instagram');
    }
    throw new Error(label + ' failed: HTTP ' + response.status);
  }
  const r1 = await fetch('https://www.instagram.com/api/v1/users/web_profile_info/?username=' + encodeURIComponent(username), opts);
  if (r1.status === 404) throw new Error('User not found: ' + username);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the username is correct and the profile is public/accessible while logged in.
  2. Log the raw web_profile_info response to see why data.user.id is absent.
  3. Ensure the 400-response business-account fallback path (feed-by-username) returns a valid user.pk.
  4. Retry later if Instagram is returning degraded 200 responses (rate limiting).
  5. Update the parsing paths if Instagram changed its response schema.

Example fix

// before
const userId = await page.evaluate(buildResolveInstagramUserIdJs());
// after
let userId;
try { userId = await page.evaluate(buildResolveInstagramUserIdJs()); }
catch (e) {
  if (String(e.message).includes('no valid user id')) throw new Error('Profile unavailable or private: ' + username);
  throw e;
}
Defensive patterns

Strategy: validation

Validate before calling

// Before resolving, confirm the username is a clean handle
if (!/^[A-Za-z0-9._]{1,30}$/.test(username)) throw new Error('Invalid Instagram username: ' + username);

Type guard

function isNumericUserId(value) {
  const s = typeof value === 'number' ? String(value) : (typeof value === 'string' ? value.trim() : '');
  return /^\d+$/.test(s);
}

Try / catch

try {
  const userId = await page.evaluate(buildResolveInstagramUserIdJs());
  return userId;
} catch (e) {
  if (String(e.message).includes('no valid user id')) throw new Error('Profile unavailable/private: ' + username);
  throw e;
}

Prevention

When it happens

Trigger: normalizeInstagramUserId receives a non-numeric value: web_profile_info returned ok but data.user.id was missing/non-numeric, or the feed-by-username fallback's user.pk was missing — the label then surfaces verbatim as the error message.

Common situations: Private/restricted profile where data.user is null; mistyped username yielding a degraded 200 response; Instagram A/B response shape changes; rate-limited 200 responses lacking user data.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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