{"record":{"id":"0328131f74629b0b","repo":"iOfficeAI/OfficeCLI","slug":"page-ps-out-of-range-total-slides-slidecoun","errorCode":null,"errorMessage":"--page {ps} out of range (total slides: {slideCount}).","messagePattern":"--page (.+?) out of range \\(total slides: (.+?)\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.View.cs","lineNumber":770,"sourceCode":"    }\n\n    private static (int? start, int? end) ParsePptHtmlPage(\n        string? pageFilter, int? start, int? end,\n        OfficeCli.Handlers.PowerPointHandler pptHandler)\n    {\n        if (string.IsNullOrEmpty(pageFilter)) return (start, end);\n        var slideCount = pptHandler.Query(\"slide\").Count;\n        var firstTok = pageFilter.Split(',')[0].Trim();\n        // Range form \"M-N\"\n        if (firstTok.Contains('-'))\n        {\n            var parts = firstTok.Split('-', 2);\n            if (!int.TryParse(parts[0], out var ps) || !int.TryParse(parts[1], out var pe))\n                throw new ArgumentException($\"Invalid --page value '{pageFilter}': expected N or M-N or comma list.\");\n            if (ps <= 0 || pe <= 0)\n                throw new ArgumentException($\"Invalid --page value '{pageFilter}': slide number must be >= 1.\");\n            if (ps > slideCount)\n                throw new ArgumentException($\"--page {ps} out of range (total slides: {slideCount}).\");\n            return (ps, Math.Min(pe, slideCount));\n        }\n        if (!int.TryParse(firstTok, out var p))\n            throw new ArgumentException($\"Invalid --page value '{pageFilter}': expected a positive slide number.\");\n        if (p <= 0)\n            throw new ArgumentException($\"Invalid --page value '{pageFilter}': slide number must be >= 1.\");\n        if (p > slideCount)\n            throw new ArgumentException($\"--page {p} out of range (total slides: {slideCount}).\");\n        return (p, p);\n    }\n}\n","sourceCodeStart":752,"sourceCodeEnd":782,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.View.cs#L752-L782","documentation":"Thrown by ParsePptHtmlPage while rendering a PowerPoint deck to HTML when --page is given in range form \"M-N\" and the START slide M is greater than the deck's total slide count. Only the start of the range is bounds-checked; the end N is silently clamped with Math.Min(pe, slideCount), so an over-large end never throws on its own. Slide numbers are 1-indexed.","triggerScenarios":"Running `officecli view deck.pptx --page \"5-10\"` on a deck that has only 4 slides (ps=5 > slideCount=4). Any range whose first number exceeds the live slide count, e.g. --page \"100-200\" on a 10-slide deck.","commonSituations":"A script hardcodes page numbers against a deck that was later trimmed; assuming 0-indexed slides and overshooting by one; querying slide count from a stale/older copy of the file; merging decks that changed the slide total.","solutions":["Query the live slide count first (`officecli query deck.pptx \"slide\"`) and clamp M so it is <= slideCount.","Pass a range fully inside bounds, e.g. --page \"1-4\" for a 4-slide deck.","If you only need one slide, use the single-number form --page 4 instead of a range.","Parametrize your caller to compute M from the actual slide count rather than a hardcoded constant."],"exampleFix":"// before\nofficecli view deck.pptx --page \"5-10\"   // deck has 4 slides\n// after\nofficecli query deck.pptx \"slide\"            // learn count = 4\nofficecli view deck.pptx --page \"1-4\"","handlingStrategy":"validation","validationCode":"// Resolve the slide count the same way the parser does, then clamp M.\nvar slideCount = pptHandler.Query(\"slide\").Count;\nvar m = Math.Min(requestedStart, slideCount);\nif (m < 1) m = 1;\nvar n = Math.Min(requestedEnd, slideCount);\nvar page = m == n ? $\"{m}\" : $\"{m}-{n}\";","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always query the live slide count before building a --page value.","Treat the range END as clamped (it already is) but guard the START explicitly.","Never hardcode page numbers; derive them from the actual deck."],"tags":["powerpoint","view","page-range","validation","officecli"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}