{"record":{"id":"1f2826b814f75b04","repo":"jackwener/OpenCLI","slug":"cannot-determine-active-group-id","errorCode":null,"errorMessage":"Cannot determine active group_id","messagePattern":"Cannot determine active group_id","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/zsxq/utils.js","lineNumber":74,"sourceCode":"    const cookies = await page.getCookies({ domain: SITE_DOMAIN });\n    return cookies.find(cookie => cookie.name === name)?.value;\n}\nexport async function getActiveGroupId(page) {\n    const groupId = await page.evaluate(`\n    (() => {\n      const target = localStorage.getItem('target_group');\n      if (target) {\n        try {\n          const parsed = JSON.parse(target);\n          if (parsed.group_id) return String(parsed.group_id);\n        } catch {}\n      }\n      return null;\n    })()\n  `);\n    if (groupId)\n        return groupId;\n    throw new ArgumentError('Cannot determine active group_id', 'Pass --group_id <id> or open the target 知识星球 page in Chrome first');\n}\nexport async function browserJsonRequest(page, path) {\n    return await page.evaluate(`\n    (async () => {\n      const path = ${JSON.stringify(path)};\n\n      try {\n        return await new Promise((resolve) => {\n          const xhr = new XMLHttpRequest();\n          xhr.open('GET', path, true);\n          xhr.withCredentials = true;\n          xhr.setRequestHeader('accept', 'application/json, text/plain, */*');\n          xhr.onload = () => {\n            let parsed = null;\n            if (xhr.responseText) {\n              try { parsed = JSON.parse(xhr.responseText); }\n              catch {}\n            }","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zsxq/utils.js#L56-L92","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass --group_id <id> explicitly on the command line","Open the target 知识星球 group page (xxx.zsxq.com/group/<id>) in the managed Chrome session, then retry","Extract the group_id from the group page URL and store it in your script/config for reuse"],"exampleFix":"// before\nopencli zsxq topics\n// after\nopencli zsxq topics --group_id 48552118818451","handlingStrategy":"validation","validationCode":"const groupId = args.group_id ?? process.env.ZSXQ_GROUP_ID;\nif (!groupId) throw new Error('Provide --group_id (or set ZSXQ_GROUP_ID) or open the group page in Chrome');","typeGuard":"const hasGroupId = (v) => typeof v === 'string' && /^\\d+$/.test(v.trim());","tryCatchPattern":"try {\n  await cmd();\n} catch (e) {\n  if (e instanceof ArgumentError && /group_id/.test(e.message)) {\n    console.error('Pass --group_id <id> or open the target 知识星球 page first');\n  } else throw e;\n}","preventionTips":["Always pass --group_id in scripts/CI instead of relying on the active page","Store group ids in config once discovered from the group page URL","Verify the managed browser is actually on a group detail page before omitting the flag"],"tags":["argument","browser","configuration"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}