{"record":{"id":"b45c15fadeabce81","repo":"jackwener/OpenCLI","slug":"failed-to-execute-geogebra-command-err-message","errorCode":null,"errorMessage":"Failed to execute GeoGebra command: ${err?.message || err}","messagePattern":"Failed to execute GeoGebra command: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/geogebra/utils.js","lineNumber":154,"sourceCode":"          return Array.isArray(names) ? names : [];\n        };\n        const beforeCount = collectNames().length;\n        const label = ggbApplet.evalCommandGetLabels(cmd);\n        const afterCount = collectNames().length;\n        const dialogText = [...document.querySelectorAll('[role=\"dialog\"], .gwt-DialogBox')]\n          .map(node => node.textContent?.trim() || '')\n          .find(text => /error|unknown command|错误|未知的指令/i.test(text)) || '';\n        return {\n          ok: label !== '' || afterCount > beforeCount,\n          label,\n          beforeCount,\n          afterCount,\n          error: dialogText || null,\n        };\n      })(${JSON.stringify(cmd)})\n    `));\n  } catch (err) {\n    throw new CommandExecutionError(`Failed to execute GeoGebra command: ${err?.message || err}`);\n  }\n  if (!isPlainObject(result) || typeof result.ok !== 'boolean') {\n    throw new CommandExecutionError('GeoGebra command returned malformed result');\n  }\n  return result;\n}\n\n/**\n * List all currently known GeoGebra objects, optionally filtered by type.\n */\nexport async function ggbListObjects(page, filterType) {\n  const normalizedFilter = filterType ? String(filterType).toLowerCase() : '';\n  let objects;\n  try {\n    objects = unwrapBridgeEnvelope(await page.evaluate(`\n      (filterType => {\n        const api = ggbApplet;\n        let names = api.getAllObjectNames();","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/geogebra/utils.js#L136-L172","documentation":"ggbEval() runs a GeoGebra command string through ggbApplet.evalCommandGetLabels inside the page. If the page.evaluate call itself rejects — the command script throws, the page context is destroyed, or evaluation times out — it throws CommandExecutionError 'Failed to execute GeoGebra command: ...' wrapping the underlying error. This is a transport/evaluation failure, distinct from command-level GeoGebra errors reported via result.ok=false.","triggerScenarios":"The in-page async helper throws unexpectedly (dialog detection code hitting a detached DOM node), execution context destroyed mid-evaluation, page crashed during evalCommand for a huge construction, or the page navigated away while the command ran.","commonSituations":"Very large/complex commands freezing the renderer until evaluate times out, concurrent tools driving the same page causing re-entrancy, automation framework closing pages between steps, or GeoGebra UI dialogs (e.g. save prompts) stealing focus and breaking the helper's assumptions.","solutions":["Read the wrapped err message: 'Target closed'/'context destroyed' means recreate or re-navigate the page, then retry.","Retry the command once after ensureApplet(page) — transient dialog/DOM races usually clear.","Reduce command complexity (split large constructions into multiple evalCommand calls) to avoid renderer freezes.","Serialize access to the page: don't run multiple tools concurrently against the same browser tab."],"exampleFix":"// before\nawait ggbEval(page, hugeCommand); // evaluate times out\n// after\nfor (const c of splitCommands(hugeCommand)) await ggbEval(page, c);","handlingStrategy":"try-catch","validationCode":"if (page.isClosed() || !page.url().includes('geogebra.org/geometry')) await ensureApplet(page);","typeGuard":"null","tryCatchPattern":"try { await ggbEval(page, cmd); } catch (e) { if (String(e.message).includes('Failed to execute')) { await ensureApplet(page); await ggbEval(page, cmd); } else throw e; }","preventionTips":["Keep commands modest in size; split big constructions.","Never run concurrent tools against the same tab.","Dismiss/avoid GeoGebra UI dialogs before executing commands.","Recreate the page after context-destroyed errors instead of retrying in place."],"tags":["browser","automation","page-evaluation","geogebra"],"backgroundTag":"browser-page-evaluation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}