iOfficeAI/OfficeCLI · error · ArgumentException

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

Error message

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

What it means

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.

Source

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

    }

    private static (int? start, int? end) ParsePptHtmlPage(
        string? pageFilter, int? start, int? end,
        OfficeCli.Handlers.PowerPointHandler pptHandler)
    {
        if (string.IsNullOrEmpty(pageFilter)) return (start, end);
        var slideCount = pptHandler.Query("slide").Count;
        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 live slide count first (`officecli query deck.pptx "slide"`) and clamp M so it is <= slideCount.
  2. Pass a range fully inside bounds, e.g. --page "1-4" for a 4-slide deck.
  3. If you only need one slide, use the single-number form --page 4 instead of a range.
  4. Parametrize your caller to compute M from the actual slide count rather than a hardcoded constant.

Example fix

// before
officecli view deck.pptx --page "5-10"   // deck has 4 slides
// after
officecli query deck.pptx "slide"            // learn count = 4
officecli view deck.pptx --page "1-4"
Defensive patterns

Strategy: validation

Validate before calling

// Resolve the slide count the same way the parser does, then clamp M.
var slideCount = pptHandler.Query("slide").Count;
var m = Math.Min(requestedStart, slideCount);
if (m < 1) m = 1;
var n = Math.Min(requestedEnd, slideCount);
var page = m == n ? $"{m}" : $"{m}-{n}";

Prevention

When it happens

Trigger: 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.

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

Related errors


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