{"record":{"id":"8cf977e070b37b08","repo":"iOfficeAI/OfficeCLI","slug":"range-target-not-found","errorCode":"range_target_not_found","errorMessage":"--range target '{clipArg}' matched no rendered element.","messagePattern":"--range target '(.+?)' matched no rendered element\\.","errorType":"exception","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.View.cs","lineNumber":463,"sourceCode":"\n                var pngPath = outArg ?? Path.Combine(Path.GetTempPath(), $\"officecli_screenshot_{Path.GetFileNameWithoutExtension(file.Name)}_{DateTime.Now:HHmmss}_{Guid.NewGuid():N}.png\");\n                if (directPng != null)\n                {\n                    File.WriteAllBytes(pngPath, directPng);\n                }\n                else\n                {\n                    // SECURITY: random token in temp filename — same rationale as the html/--browser path.\n                    var tmpHtml = Path.Combine(Path.GetTempPath(), $\"officecli_preview_{Path.GetFileNameWithoutExtension(file.Name)}_{DateTime.Now:HHmmss}_{Guid.NewGuid():N}.html\");\n                    File.WriteAllText(tmpHtml, html!);\n                    var r = clipArg != null\n                        ? OfficeCli.Core.HtmlScreenshot.CaptureClipped(tmpHtml, pngPath,\n                            OfficeCli.Core.HtmlScreenshot.ResolveClipDataPaths(clipArg))\n                        : OfficeCli.Core.HtmlScreenshot.Capture(tmpHtml, pngPath, screenshotWidth, screenshotHeight);\n                    try { File.Delete(tmpHtml); } catch { /* ignore */ }\n                    if (!r.Ok && r.Error == \"clip_target_not_found\")\n                    {\n                        throw new OfficeCli.Core.CliException(\n                            $\"--range target '{clipArg}' matched no rendered element.\")\n                        {\n                            Code = \"range_target_not_found\",\n                            Suggestion = \"Use a data-path the HTML preview emits (xlsx: 'Sheet1!A1:C3' within the sheet's used area; pptx: '/slide[N]/shape[K]'; docx: '/body/table[N]' or '/body/p[N]'). `query` lists element paths.\",\n                        };\n                    }\n                    if (!r.Ok)\n                    {\n                        throw new OfficeCli.Core.CliException(\n                            \"No headless browser available. Install Chrome/Edge/Chromium or Firefox, or `pip install playwright && playwright install chromium`.\"\n                            + (r.Error != null ? $\" Last error: {r.Error}\" : \"\"))\n                        { Code = \"no_screenshot_backend\" };\n                    }\n                }\n                Console.WriteLine(Path.GetFullPath(pngPath));\n                if (handler is OfficeCli.Handlers.PowerPointHandler pptCount)\n                    Console.Error.WriteLine($\"[pages] total={pptCount.GetSlideCount()}\");\n                if (browser)","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.View.cs#L445-L481","documentation":"The --range clip path renders the full HTML preview then calls HtmlScreenshot.CaptureClipped with ResolveClipDataPaths(clipArg). When the headless browser loaded the page but the clip selector matched zero elements, CaptureClipped returns Ok=false with Error=\"clip_target_not_found\", and this CliException surfaces it. It means the data-path syntax was valid but pointed at nothing the preview actually emitted (e.g. a shape index that does not exist, a cell range outside the used area).","triggerScenarios":"`view --mode screenshot --range '/slide[9]/shape[4]' deck.pptx` where the deck has fewer than 9 slides or slide 9 has no shape 4; `--range 'Sheet1!Z100' book.xlsx` beyond the used range; `--range '/body/table[3]' doc.docx` with fewer than 3 tables. The selector parsed fine but matched no DOM node.","commonSituations":"Off-by-one shape/table indices; referencing a sheet/cell outside the used area; stale data-path copied from a different document version; wrong path grammar for the format (pptx uses /slide[N]/shape[K], docx uses /body/table[N] or /body/p[N]).","solutions":["Run `query` on the file to list the element paths the preview actually emits, then copy an exact path","Confirm the index is within bounds (slide count, table count, used cell range)","Use the correct grammar for the format (xlsx: Sheet1!A1:C3; pptx: /slide[N]/shape[K]; docx: /body/table[N] or /body/p[N])","Drop --range to capture the whole preview and verify the element exists"],"exampleFix":"// before\nofficecli view --mode screenshot --range '/slide[9]/shape[4]' deck.pptx\n// after (discover valid paths first)\nofficecli query deck.pptx   // then use a path it lists, e.g.:\nofficecli view --mode screenshot --range '/slide[2]/shape[1]' deck.pptx","handlingStrategy":"validation","validationCode":"// Discover valid element paths before clipping.\n// 1) Run `query` on the file to list emitted data-paths.\n// 2) Verify the intended --range path appears in that list.\nvar knownPaths = QueryElements(file); // your call to the `query` surface\nstring range = \"/slide[2]/shape[1]\";\nif (!knownPaths.Contains(range))\n{\n    // pick a path from knownPaths instead of risking range_target_not_found\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    // invoke view --mode screenshot --range path file\n}\ncatch (OfficeCli.Core.CliException ex) when (ex.Code == \"range_target_not_found\")\n{\n    // re-query the file for valid paths and retry with one of them\n}","preventionTips":["Always run `query` first to list the data-paths the preview emits","Use the format-correct grammar (xlsx Sheet1!A1:C3; pptx /slide[N]/shape[K]; docx /body/table[N])","Keep indices within bounds (slide/table/cell counts)","Avoid copying --range paths from a different document version"],"tags":["range","clip","screenshot","html","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}