{"record":{"id":"ad5f4a01ddf45a95","repo":"iOfficeAI/OfficeCLI","slug":"page-p-out-of-range-total-slides-slidecount","errorCode":null,"errorMessage":"--page {p} 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":778,"sourceCode":"        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":760,"sourceCodeEnd":782,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.View.cs#L760-L782","documentation":"Thrown by ParsePptHtmlPage in the single-number branch when the token is a valid positive integer but exceeds the deck's total slide count. Unlike the range form (where the end is clamped), a single over-large page number has nothing to clamp to, so it errors.","triggerScenarios":"`officecli view deck.pptx --page 10` on a 5-slide deck; `--page 100` on a freshly created 1-slide deck.","commonSituations":"Hardcoded page numbers in a script run against a smaller deck; deck was edited/reduced after the script was written; pointing at the wrong file with fewer slides than expected.","solutions":["Query the slide count first and pass a number <= slideCount.","Clamp the requested page: page = Math.Min(requested, slideCount).","Verify you are pointing at the intended file (slide totals differ between drafts).","Prefer the range form if you want graceful clamping of the upper bound."],"exampleFix":"// before\nofficecli view deck.pptx --page 10           // deck has 5 slides\n// after\nofficecli view deck.pptx --page 5","handlingStrategy":"validation","validationCode":"var slideCount = pptHandler.Query(\"slide\").Count;\nvar page = Math.Clamp(requested, 1, Math.Max(1, slideCount));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Query the slide count and clamp the page to it.","Prefer the range form if you want the upper bound clamped automatically.","Re-check the count if the deck may have been edited."],"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"}