d2phap/ImageGlass Β· error Β· ArgumentException
'{modeStr}' is not a valid zoom mode. ---------- ππΌ Metho
Error message
'{modeStr}' is not a valid zoom mode.
----------
ππΌ Method: IG_SetZoomMode What it means
Thrown by the string overload of IG_SetZoomMode when Enum.TryParse<ZoomMode>(modeStr) fails. ZoomMode is case-insensitively parsed; valid names are AutoZoom, LockZoom, ScaleToWidth, ScaleToHeight, ScaleToFit, ScaleToFill. Any other string raises ArgumentException.
Source
Thrown at source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs:1247
if (Viewer.ZoomFactor < 1)
{
IG_SetZoom(1);
}
else
{
IG_Refresh();
}
}
/// <summary>
/// Sets the zoom mode value.
/// </summary>
public void IG_SetZoomMode(string? modeStr)
{
if (!Enum.TryParse<ZoomMode>(modeStr, out var mode))
{
throw new ArgumentException($"""
'{modeStr}' is not a valid zoom mode.
----------
ππΌ Method: {nameof(IG_SetZoomMode)}
""",
nameof(modeStr));
}
IG_SetZoomMode(mode);
}
/// <summary>
/// Sets the zoom mode value.
/// </summary>
public static void IG_SetZoomMode(ZoomMode mode)
{
if (mode == Core.Config.ZoomMode)
{View on GitHub (pinned to 4a3c4fecef)
Solutions
- Use one of the exact enum names: AutoZoom, LockZoom, ScaleToWidth, ScaleToHeight, ScaleToFit, ScaleToFill.
- Validate with Enum.TryParse<ZoomMode> upstream and pass the enum to the typed overload.
- Trim whitespace and map user aliases to the canonical name before calling.
Example fix
// before
api.IG_SetZoomMode(userInput);
// after
if (Enum.TryParse<ZoomMode>(userInput?.Trim(), true, out var mode))
{
api.IG_SetZoomMode(mode);
} Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.TryParse<ZoomMode>(modeStr?.Trim(), true, out var mode))
throw new ArgumentException($"Unknown zoom mode '{modeStr}'.");
api.IG_SetZoomMode(mode); Type guard
static bool IsValidZoomMode(string? s) => Enum.TryParse<ZoomMode>(s?.Trim(), true, out _);
Try / catch
try { api.IG_SetZoomMode(modeStr); }
catch (ArgumentException ex) when (ex.ParamName == nameof(modeStr))
{ /* valid: AutoZoom, LockZoom, ScaleToWidth, ScaleToHeight, ScaleToFit, ScaleToFill */ } Prevention
- Use exact enum names; map short aliases upstream.
- Validate with Enum.TryParse<ZoomMode> before calling.
- Trim whitespace and reject empty input.
When it happens
Trigger: Calling IG_SetZoomMode(string) with a value not in the enum: 'fit' (use 'ScaleToFit'), 'lock' (use 'LockZoom'), 'fill', 'auto', or a numeric string (Enum.TryParse accepts numeric strings for the underlying int, but a non-numeric label that is not a member name fails).
Common situations: User types a short alias instead of the full enum name; config authored with a legacy or v9 name; casing or a trailing space in the value.
Related errors
- Zoom factor '{factorStr}' is not a valid float. ----------
- '{orderByStr}' is not a valid loading order. ---------- ποΏ½
- '{orderTypeStr}' is not a valid loading order. ---------- οΏ½
- '{channelsStr}' is not a valid color channel. ---------- π
- '{optionStr}' is not a valid rotation option. ---------- π
AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13).
Data as JSON: /api/errors/c5a4e49646f3fd2d.
Report an issue: GitHub.