{"record":{"id":"c5a4e49646f3fd2d","repo":"d2phap/ImageGlass","slug":"modestr-is-not-a-valid-zoom-mode","errorCode":null,"errorMessage":"'{modeStr}' is not a valid zoom mode.\n\n----------\n👉🏼 Method: IG_SetZoomMode","messagePattern":"'(.+?)' is not a valid zoom mode\\.\n\n----------\n👉🏼 Method: IG_SetZoomMode","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs","lineNumber":1247,"sourceCode":"        if (Viewer.ZoomFactor < 1)\n        {\n            IG_SetZoom(1);\n        }\n        else\n        {\n            IG_Refresh();\n        }\n    }\n\n\n    /// <summary>\n    /// Sets the zoom mode value.\n    /// </summary>\n    public void IG_SetZoomMode(string? modeStr)\n    {\n        if (!Enum.TryParse<ZoomMode>(modeStr, out var mode))\n        {\n            throw new ArgumentException($\"\"\"\n                '{modeStr}' is not a valid zoom mode.\n\n                ----------\n                👉🏼 Method: {nameof(IG_SetZoomMode)}\n                \"\"\",\n                nameof(modeStr));\n        }\n\n        IG_SetZoomMode(mode);\n    }\n\n    /// <summary>\n    /// Sets the zoom mode value.\n    /// </summary>\n    public static void IG_SetZoomMode(ZoomMode mode)\n    {\n        if (mode == Core.Config.ZoomMode)\n        {","sourceCodeStart":1229,"sourceCodeEnd":1265,"githubUrl":"https://github.com/d2phap/ImageGlass/blob/4a3c4feceffc5a8bb5e56ba836509634aaae47a9/source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs#L1229-L1265","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\napi.IG_SetZoomMode(userInput);\n\n// after\nif (Enum.TryParse<ZoomMode>(userInput?.Trim(), true, out var mode))\n{\n    api.IG_SetZoomMode(mode);\n}","handlingStrategy":"validation","validationCode":"if (!Enum.TryParse<ZoomMode>(modeStr?.Trim(), true, out var mode))\n    throw new ArgumentException($\"Unknown zoom mode '{modeStr}'.\");\napi.IG_SetZoomMode(mode);","typeGuard":"static bool IsValidZoomMode(string? s) => Enum.TryParse<ZoomMode>(s?.Trim(), true, out _);","tryCatchPattern":"try { api.IG_SetZoomMode(modeStr); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(modeStr))\n{ /* valid: AutoZoom, LockZoom, ScaleToWidth, ScaleToHeight, ScaleToFit, ScaleToFill */ }","preventionTips":["Use exact enum names; map short aliases upstream.","Validate with Enum.TryParse<ZoomMode> before calling.","Trim whitespace and reject empty input."],"tags":["app-api","zoom","argument-parsing","enum"],"backgroundTag":null,"analyzedSha":"4a3c4feceffc5a8bb5e56ba836509634aaae47a9","analyzedAt":"2026-08-13T16:58:15.523Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}