jackwener/OpenCLI · error · ArgumentError

Cannot determine active group_id

Error message

Cannot determine active group_id

What it means

getActiveGroupId tries to discover the currently active 知识星球 group_id by evaluating JavaScript in the live page (reading the group id from the open ZSXQ page). When the page evaluation returns null (no group page open or no id extractable) it throws this ArgumentError telling the user to supply the id explicitly. It exists because ZSXQ API endpoints require a group_id the library cannot always infer.

Source

Thrown at clis/zsxq/utils.js:74

    const cookies = await page.getCookies({ domain: SITE_DOMAIN });
    return cookies.find(cookie => cookie.name === name)?.value;
}
export async function getActiveGroupId(page) {
    const groupId = await page.evaluate(`
    (() => {
      const target = localStorage.getItem('target_group');
      if (target) {
        try {
          const parsed = JSON.parse(target);
          if (parsed.group_id) return String(parsed.group_id);
        } catch {}
      }
      return null;
    })()
  `);
    if (groupId)
        return groupId;
    throw new ArgumentError('Cannot determine active group_id', 'Pass --group_id <id> or open the target 知识星球 page in Chrome first');
}
export async function browserJsonRequest(page, path) {
    return await page.evaluate(`
    (async () => {
      const path = ${JSON.stringify(path)};

      try {
        return await new Promise((resolve) => {
          const xhr = new XMLHttpRequest();
          xhr.open('GET', path, true);
          xhr.withCredentials = true;
          xhr.setRequestHeader('accept', 'application/json, text/plain, */*');
          xhr.onload = () => {
            let parsed = null;
            if (xhr.responseText) {
              try { parsed = JSON.parse(xhr.responseText); }
              catch {}
            }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass --group_id <id> explicitly on the command line
  2. Open the target 知识星球 group page (xxx.zsxq.com/group/<id>) in the managed Chrome session, then retry
  3. Extract the group_id from the group page URL and store it in your script/config for reuse

Example fix

// before
opencli zsxq topics
// after
opencli zsxq topics --group_id 48552118818451
Defensive patterns

Strategy: validation

Validate before calling

const groupId = args.group_id ?? process.env.ZSXQ_GROUP_ID;
if (!groupId) throw new Error('Provide --group_id (or set ZSXQ_GROUP_ID) or open the group page in Chrome');

Type guard

const hasGroupId = (v) => typeof v === 'string' && /^\d+$/.test(v.trim());

Try / catch

try {
  await cmd();
} catch (e) {
  if (e instanceof ArgumentError && /group_id/.test(e.message)) {
    console.error('Pass --group_id <id> or open the target 知识星球 page first');
  } else throw e;
}

Prevention

When it happens

Trigger: Invoking a command that calls groupId without --group_id while no 知识星球 group page is open in the Chrome session, or the open page is not a group detail page so the in-page script returns null.

Common situations: Running headless/automation where no one opened a group page; being on the zsxq home page or a topic page instead of the group page; forgetting the --group_id flag in scripts/CI.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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