d2phap/ImageGlass Β· error Β· ArgumentException

'{optionStr}' is not a valid flip option. ---------- πŸ‘‰πŸΌ M

Error message

'{optionStr}' is not a valid flip option.

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

What it means

Thrown by the string overload of IG_FlipImage when Enum.TryParse<FlipOptions>(optionStr) fails. FlipOptions is a [Flags] enum; valid names are None, Horizontal, and Vertical. Combinations like 'Horizontal,Vertical' are accepted case-insensitively. Any token not in the set fails the whole parse.

Source

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

            Core.ImageTransform.Rotation = currentRotation;
        }
        else
        {
            _ = Message.ShowAsync(
                Core.Lang[LangId._InvalidAction_Transformation],
                Core.Lang[LangId._InvalidAction]);
        }
    }


    /// <summary>
    /// Flips the current image according to the flip options.
    /// </summary>
    public void IG_FlipImage(string? optionStr)
    {
        if (!Enum.TryParse<FlipOptions>(optionStr, out var options))
        {
            throw new ArgumentException($"""
                '{optionStr}' is not a valid flip option.

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

        IG_FlipImage(options);
    }


    /// <summary>
    /// Flips the current image according to the flip options.
    /// </summary>
    public static void IG_FlipImage(FlipOptions options)
    {
        if (Viewer.SourceKind == PhotoSource.None || Core.IsBusy) return;

View on GitHub (pinned to 4a3c4fecef)

Solutions

  1. Use None, Horizontal, Vertical, or a comma-separated combination such as 'Horizontal,Vertical'.
  2. Validate with Enum.TryParse<FlipOptions> upstream and call the typed overload.
  3. Trim each token in a comma-separated list before parsing.

Example fix

// before
api.IG_FlipImage(userInput);

// after
if (Enum.TryParse<FlipOptions>(userInput?.Trim(), true, out var opt))
{
    api.IG_FlipImage(opt);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!Enum.TryParse<FlipOptions>(optionStr?.Trim(), true, out var opt))
    throw new ArgumentException($"Unknown flip option '{optionStr}'.");
api.IG_FlipImage(opt);

Type guard

static bool IsValidFlipOption(string? s) => Enum.TryParse<FlipOptions>(s?.Trim(), true, out _);

Try / catch

try { api.IG_FlipImage(optionStr); }
catch (ArgumentException ex) when (ex.ParamName == nameof(optionStr))
{ /* valid: None, Horizontal, Vertical, or 'Horizontal,Vertical' */ }

Prevention

When it happens

Trigger: Calling IG_FlipImage(string) with 'h'/'v', 'flip-h', 'both' (use 'Horizontal,Vertical'), 'horizontal ' with a trailing space inside the token, or 'mirror'.

Common situations: User types a short alias instead of the full name; config with a non-defined combination; trailing whitespace inside a comma list.

Related errors


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