d2phap/ImageGlass Β· error Β· ArgumentException

Frame index '{frameIndexStr}' is not a valid integer. -----

Error message

Frame index '{frameIndexStr}' is not a valid integer.

----------
πŸ‘‰πŸΌ Method: IG_ViewFrame

What it means

Thrown by the string overload of IG_ViewFrame when int.TryParse(frameIndexStr) fails. The method parses a frame index for a multi-frame photo (GIF/WEBP animation) before delegating to the int overload. Out-of-range indices are looped safely downstream; only a non-integer string throws here.

Source

Thrown at source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs:1095


    /// <summary>
    /// Views the last photo in the list.
    /// </summary>
    public void IG_GoToLast()
    {
        IG_ViewByIndex((int)Core.Photos.Count - 1);
    }


    /// <summary>
    /// View a frame of the current photo.
    /// </summary>
    public void IG_ViewFrame(string? frameIndexStr)
    {
        if (!int.TryParse(frameIndexStr, out var frameIndex))
        {
            throw new ArgumentException($"""
                Frame index '{frameIndexStr}' is not a valid integer.

                ----------
                πŸ‘‰πŸΌ Method: {nameof(IG_ViewFrame)}
                """,
                nameof(frameIndexStr));
        }

        IG_ViewFrame(frameIndex);
    }


    /// <summary>
    /// View a frame of the current photo.
    /// If the frame index is out of range, it will be looped.
    /// </summary>
    public static void IG_ViewFrame(int frameIndex)
    {

View on GitHub (pinned to 4a3c4fecef)

Solutions

  1. Pass a plain integer string for the frame index ('0', '1', '2', ...).
  2. Validate with int.TryParse upstream and call the int overload directly.
  3. Trim and reject empty input before invoking.

Example fix

// before
api.IG_ViewFrame(userInput);

// after
if (int.TryParse(userInput?.Trim(), out var frame))
{
    api.IG_ViewFrame(frame);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!int.TryParse(frameIndexStr?.Trim(), out var frame))
    throw new ArgumentException("Frame index must be an integer.");
api.IG_ViewFrame(frame);

Type guard

static bool IsValidFrameIndex(string? s) => int.TryParse(s?.Trim(), out _);

Try / catch

try { api.IG_ViewFrame(frameIndexStr); }
catch (ArgumentException ex) when (ex.ParamName == nameof(frameIndexStr))
{ /* reject the input */ }

Prevention

When it happens

Trigger: Calling IG_ViewFrame(string) with a non-numeric frame index: 'first', '2.5', '' , or a string with whitespace.

Common situations: Hotkey bound to a frame navigation command with a non-numeric argument; script passing a label instead of an index; current photo is single-frame (the int overload returns early, but the string parse happens first).

Related errors


AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13). Data as JSON: /api/errors/2030aef706f14042. Report an issue: GitHub.