{"record":{"id":"0d5b49461586456e","repo":"jackwener/OpenCLI","slug":"antigravity-copy-code","errorCode":null,"errorMessage":"antigravity copy-code","messagePattern":"antigravity copy-code","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"error","filePath":"clis/antigravity/audit-extras.js","lineNumber":164,"sourceCode":"        { name: 'index', type: 'int', required: false, help: '1-based index of code block (default: last)' },\n    ],\n    columns: ['Field', 'Value'],\n    func: async (page, kwargs) => {\n        const idx = Number.isInteger(kwargs?.index) ? kwargs.index : null;\n        const data = unwrapEvaluateResult(await page.evaluate(`(() => {\n      const isVis = (el) => { const r = el.getBoundingClientRect(); return r.width > 1 && r.height > 1; };\n      const btns = Array.from(document.querySelectorAll('button[aria-label=\"Copy code\"]')).filter(isVis);\n      if (!btns.length) return null;\n      const idx = ${idx === null ? 'btns.length - 1' : (idx - 1)};\n      const btn = btns[idx];\n      if (!btn) return { err: 'index ' + (${idx} ?? 'last') + ' out of range. Have ' + btns.length + ' code blocks.' };\n      // Find the <code> or <pre> element inside the parent block.\n      let container = btn;\n      for (let i = 0; i < 6 && container.parentElement; i++) container = container.parentElement;\n      const code = container.querySelector('pre, code');\n      return { text: code ? (code.innerText || '').trim() : (container.innerText || '').trim(), total: btns.length };\n    })()`));\n        if (!data) throw new EmptyResultError('antigravity copy-code', 'No code blocks visible.');\n        if (data.err) throw new CommandExecutionError(data.err, '');\n        return [\n            { Field: 'TotalCodeBlocks', Value: String(data.total) },\n            { Field: 'PickedIndex', Value: String(idx === null ? data.total : idx) },\n            { Field: 'Length', Value: String((data.text || '').length) + ' chars' },\n            { Field: 'Code', Value: data.text || '' },\n        ];\n    },\n});\n\n// -------- settings --------\ncli({\n    site: 'antigravity',\n    name: 'settings',\n    access: 'write',\n    description: 'Click the Antigravity settings button (matched by data-testid=\"settings-button\").',\n    domain: '127.0.0.1',\n    strategy: Strategy.UI,","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/antigravity/audit-extras.js#L146-L182","documentation":"EmptyResultError (code 'EMPTY_RESULT') from 'antigravity copy-code': the in-page script found zero Copy buttons associated with code blocks (`btns.length === 0`) or returned nothing, so there is no code text to report. The message names the command ('antigravity copy-code returned no data') with hint 'No code blocks visible.' It reflects page state, not a bug in your arguments.","triggerScenarios":"Running `antigravity copy-code` (with or without an index) when the visible assistant replies contain no code blocks — the scrape finds no copy-code buttons and `if (!data)` throws.","commonSituations":"The current reply is prose-only with no fenced code; the conversation is empty; code blocks are rendered without the expected copy button in a newer Antigravity version; you are scrolled to a part of the chat without code.","solutions":["Scroll to / render an assistant reply that contains a fenced code block, then re-run.","Run `antigravity copy-message` first to confirm assistant content is visible at all.","If code blocks exist but have no copy button, the UI changed — update the button-matching selector in audit-extras.js.","Verify you are attached to the right conversation/tab."],"exampleFix":"// before\nantigravity copy-code 0   // no code blocks on screen\n\n// after\n# ensure a reply containing code is rendered, then:\nantigravity copy-code 0","handlingStrategy":"validation","validationCode":"// Confirm code blocks exist before invoking copy-code\nconst codeCount = await page.evaluate(\"document.querySelectorAll('pre, code').length\");\nif (!codeCount) throw new Error('No code blocks rendered on screen.');","typeGuard":"function hasCodeData(data) {\n  return data != null && typeof data === 'object'\n    && typeof data.total === 'number' && data.total > 0\n    && typeof data.text === 'string';\n}","tryCatchPattern":"try {\n  const rows = await runCmd('antigravity copy-code 0');\n} catch (e) {\n  if (e.code === 'EMPTY_RESULT') {\n    console.error('No code blocks visible — render a reply containing fenced code first.');\n  } else throw e;\n}","preventionTips":["Ensure the visible reply actually contains fenced code blocks.","Verify a Copy button exists on code blocks in the current Antigravity version.","Use copy-message first to confirm assistant content is rendered.","Keep index within the returned TotalCodeBlocks range."],"tags":["empty-result","dom-scrape","code-block"],"backgroundTag":"empty-page-scrape-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}