d2phap/ImageGlass Β· error Β· ArgumentException
Step '{stepStr}' is not a valid integer. ---------- ππΌ Me
Error message
Step '{stepStr}' is not a valid integer.
----------
ππΌ Method: IG_ViewByStep What it means
Thrown by the string overload of IG_ViewByStep when int.TryParse(stepStr) fails. The method parses a navigation step (positive = forward, negative = backward) from a string before delegating to the int overload. A null or non-integer string raises ArgumentException naming the parameter.
Source
Thrown at source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs:901
/// View a photo in the list by the given index.
/// </summary>
public void IG_ViewByIndex(int photoIndex)
{
if (photoIndex < 0) return;
var step = photoIndex - Core.Photos.CurrentIndex;
IG_ViewByStep(step);
}
/// <summary>
/// View a photo in the list by the given step.
/// </summary>
public void IG_ViewByStep(string? stepStr)
{
if (!int.TryParse(stepStr, out var step))
{
throw new ArgumentException($"""
Step '{stepStr}' is not a valid integer.
----------
ππΌ Method: {nameof(IG_ViewByStep)}
""",
nameof(stepStr));
}
IG_ViewByStep(step);
}
/// <summary>
/// View a photo in the list by the given step.
/// </summary>
public void IG_ViewByStep(int step)
{
// Sequential mode: ignore navigation until the current photo is painted, so holdingView on GitHub (pinned to 4a3c4fecef)
Solutions
- Pass a plain integer string such as '1', '-1', '5' (no plus sign, no decimals, no surrounding spaces).
- Validate with int.TryParse before calling and use the int overload directly.
- Trim whitespace and reject empty input upstream.
Example fix
// before
api.IG_ViewByStep(userInput);
// after
if (int.TryParse(userInput?.Trim(), out var step))
{
api.IG_ViewByStep(step);
} Defensive patterns
Strategy: validation
Validate before calling
if (!int.TryParse(stepStr?.Trim(), out var step))
throw new ArgumentException("Step must be an integer.");
api.IG_ViewByStep(step); Type guard
static bool IsValidStep(string? s) => int.TryParse(s?.Trim(), out _);
Try / catch
try { api.IG_ViewByStep(stepStr); }
catch (ArgumentException ex) when (ex.ParamName == nameof(stepStr))
{ /* reject the input, prompt again */ } Prevention
- Pass plain integer strings without '+', decimals, or surrounding spaces.
- Validate upstream with int.TryParse and call the int overload.
- Trim user input before parsing.
When it happens
Trigger: Calling IG_ViewByStep(string) with a non-numeric string: 'next', '+1', '1.0', '' (note: empty string fails TryParse), or a value with a leading/trailing space.
Common situations: Hotkey or CLI argument passed as a word rather than a number; config file with a quoted string; user-typed input in a custom command that was not sanitized.
Related errors
- Frame index '{frameIndexStr}' is not a valid integer. -----
- Zoom factor '{factorStr}' is not a valid float. ----------
- '{modeStr}' is not a valid zoom mode. ---------- ππΌ Metho
- '{orderByStr}' is not a valid loading order. ---------- ποΏ½
- '{orderTypeStr}' is not a valid loading order. ---------- οΏ½
AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13).
Data as JSON: /api/errors/d39e74a649d68a03.
Report an issue: GitHub.