iOfficeAI/OfficeCLI · error · ArgumentException

--page {p} out of range (total slides: {slideCount}).

Error message

--page {p} out of range (total slides: {slideCount}).

What it means

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.

Source

Thrown at src/officecli/CommandBuilder.View.cs:778

        var firstTok = pageFilter.Split(',')[0].Trim();
        // Range form "M-N"
        if (firstTok.Contains('-'))
        {
            var parts = firstTok.Split('-', 2);
            if (!int.TryParse(parts[0], out var ps) || !int.TryParse(parts[1], out var pe))
                throw new ArgumentException($"Invalid --page value '{pageFilter}': expected N or M-N or comma list.");
            if (ps <= 0 || pe <= 0)
                throw new ArgumentException($"Invalid --page value '{pageFilter}': slide number must be >= 1.");
            if (ps > slideCount)
                throw new ArgumentException($"--page {ps} out of range (total slides: {slideCount}).");
            return (ps, Math.Min(pe, slideCount));
        }
        if (!int.TryParse(firstTok, out var p))
            throw new ArgumentException($"Invalid --page value '{pageFilter}': expected a positive slide number.");
        if (p <= 0)
            throw new ArgumentException($"Invalid --page value '{pageFilter}': slide number must be >= 1.");
        if (p > slideCount)
            throw new ArgumentException($"--page {p} out of range (total slides: {slideCount}).");
        return (p, p);
    }
}

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Query the slide count first and pass a number <= slideCount.
  2. Clamp the requested page: page = Math.Min(requested, slideCount).
  3. Verify you are pointing at the intended file (slide totals differ between drafts).
  4. Prefer the range form if you want graceful clamping of the upper bound.

Example fix

// before
officecli view deck.pptx --page 10           // deck has 5 slides
// after
officecli view deck.pptx --page 5
Defensive patterns

Strategy: validation

Validate before calling

var slideCount = pptHandler.Query("slide").Count;
var page = Math.Clamp(requested, 1, Math.Max(1, slideCount));

Prevention

When it happens

Trigger: `officecli view deck.pptx --page 10` on a 5-slide deck; `--page 100` on a freshly created 1-slide deck.

Common situations: 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.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/ad5f4a01ddf45a95. Report an issue: GitHub.