iOfficeAI/OfficeCLI · error · ArgumentException
Invalid --page value '{pageFilter}': expected N or M-N or co
Error message
Invalid --page value '{pageFilter}': expected N or M-N or comma list. What it means
ParsePptHtmlPage handles the range form 'M-N' for pptx html previews. It splits on '-' into two tokens; if either token fails int.TryParse, an ArgumentException is thrown (no Code). This is the html-mode counterpart to the SVG page parser — accepts N, M-N, and comma lists, but a non-numeric bound in a range is rejected.
Source
Thrown at src/officecli/CommandBuilder.View.cs:766
.Resolve(formatId, OfficeCli.Core.Rendering.RenderOutputKind.Png, options.Mode);
if (renderer == null) return null;
return renderer.Render(
new OfficeCli.Handlers.Rendering.HandlerRenderInput(handler, formatId), options).Bytes;
}
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
- Use integer bounds in the range, e.g. --page 1-3
- For a single slide use --page 2 (no dash)
- For a comma list ensure every token is an integer or integer range
Example fix
// before officecli view --mode html --page 1-end deck.pptx // after officecli view --mode html --page 1-3 deck.pptx
Defensive patterns
Strategy: validation
Validate before calling
// Validate a range-form --page bound for pptx html mode.
static bool IsValidPageSpec(string? pageFilter)
{
if (string.IsNullOrEmpty(pageFilter)) return true;
foreach (var tok in pageFilter.Split(','))
{
var t = tok.Trim();
if (t.Contains('-'))
{
var parts = t.Split('-', 2);
if (!int.TryParse(parts[0], out _) || !int.TryParse(parts[1], out _)) return false;
}
else if (!int.TryParse(t, out _)) return false;
}
return true;
}
if (!IsValidPageSpec(pageFilter))
{
// reject before invoking
} Type guard
bool IsValidPptxPageToken(string? pageFilter)
{
if (string.IsNullOrEmpty(pageFilter)) return true;
var firstTok = pageFilter.Split(',')[0].Trim();
if (firstTok.Contains('-'))
{
var parts = firstTok.Split('-', 2);
return int.TryParse(parts[0], out _) && int.TryParse(parts[1], out _);
}
return int.TryParse(firstTok, out _);
} Try / catch
try
{
// invoke view --mode html --page X-Y deck.pptx
}
catch (System.ArgumentException ex) when (ex.Message.Contains("expected N or M-N or comma list"))
{
// a range bound was non-numeric; reprompt for integer bounds
} Prevention
- Use integer bounds in ranges (e.g. --page 1-3)
- Validate page tokens with IsValidPptxPageToken before invoking
- For a single slide omit the dash
When it happens
Trigger: `view --mode html --page a-3 deck.pptx`, `--page 1-b`, `--page x-y`, `--page 1-` (trailing dash → empty second token). Html mode, pptx handler, range form with a non-integer bound.
Common situations: Typo in a range bound; pasting a slide-title instead of a number; a dangling dash from string concatenation; using 'last' as a bound.
Related errors
- range_target_not_found
- Invalid --page value '{pageFilter}': expected a positive sli
- Invalid --page value '{pageFilter}': slide number must be >=
- Invalid range '{spec}': offsets must be non-negative.
- --page {ps} out of range (total slides: {slideCount}).
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/56a27ef75856b68d.
Report an issue: GitHub.