iOfficeAI/OfficeCLI · error · ArgumentException

Invalid --page value '{pageFilter}': expected a positive sli

Error message

Invalid --page value '{pageFilter}': expected a positive slide number.

What it means

In SVG mode for PowerPoint, --page is parsed by taking the first comma/range token and int.TryParse-ing it. If that first token is not an integer (letters, decimals, empty), an ArgumentException is thrown (not a CliException — no Code). This surfaces invalid --page input explicitly rather than silently rendering slide 1, per the CONSISTENCY(strict-page) comment.

Source

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

                }
                return 0;
            }

            if (mode.ToLowerInvariant() is "svg" or "g")
            {
                if (handler is OfficeCli.Handlers.PowerPointHandler pptSvgHandler)
                {
                    // CONSISTENCY(view-page): SVG mode honors --page like html mode; --page wins over --start
                    int slideNum = 1;
                    if (!string.IsNullOrEmpty(pageFilter))
                    {
                        var firstTok = pageFilter.Split(',')[0].Split('-')[0].Trim();
                        // CONSISTENCY(strict-page): reject non-positive --page
                        // values explicitly instead of silently rendering
                        // slide 1, mirroring how 0 / negatives are surfaced
                        // elsewhere in the CLI.
                        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.");
                        slideNum = p;
                    }
                    else if (start.HasValue && start.Value > 0)
                    {
                        slideNum = start.Value;
                    }
                    var svg = RenderViaRegistry(handler, "pptx",
                        new OfficeCli.Core.Rendering.RenderOptions
                        { Output = OfficeCli.Core.Rendering.RenderOutputKind.Svg, StartPage = slideNum })!;

                    if (browser)
                    {
                        string outPath;
                        if (svg.Contains("data-formula"))

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Pass a positive integer to --page (e.g. --page 2)
  2. For a range use html mode (--mode html), which accepts M-N and comma lists; SVG renders one slide
  3. Strip non-numeric characters or slide labels before passing to --page

Example fix

// before
officecli view --mode svg --page two deck.pptx
// after
officecli view --mode svg --page 2 deck.pptx
Defensive patterns

Strategy: validation

Validate before calling

// Validate --page is a positive integer before SVG mode on pptx.
string firstTok = pageFilter.Split(',')[0].Split('-')[0].Trim();
if (!int.TryParse(firstTok, out int p))
{
    // reject before invoking; prompt the user for a number
}
// pass a clean integer to --page

Type guard

bool IsValidSvgPage(string? pageFilter)
{
    if (string.IsNullOrEmpty(pageFilter)) return true;
    var firstTok = pageFilter.Split(',')[0].Split('-')[0].Trim();
    return int.TryParse(firstTok, out int p) && p > 0;
}

Try / catch

try
{
    // invoke view --mode svg --page X deck.pptx
}
catch (System.ArgumentException ex) when (ex.Message.Contains("expected a positive slide number"))
{
    // --page was non-numeric; reprompt for an integer slide number
}

Prevention

When it happens

Trigger: `view --mode svg --page abc deck.pptx`, `--page 1.5`, `--page -1` (the '-' makes firstTok empty/non-int before the <=0 check), `--page ""` after trimming. SVG mode, pptx handler, non-integer first token.

Common situations: Typo in --page (letters); pasting a range like '1-3' but the code splits on '-' and the leading token is fine yet trailing token invalid triggers a different branch; using a label/slide-name instead of a number; shell quoting producing an empty string.

Related errors


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