{"record":{"id":"bf77ef6dd6f6afb9","repo":"d2phap/ImageGlass","slug":"zoom-factor-factorstr-is-not-a-valid-float","errorCode":null,"errorMessage":"Zoom factor '{factorStr}' is not a valid float.\n\n----------\n👉🏼 Method: IG_SetZoom","messagePattern":"Zoom factor '(.+?)' is not a valid float\\.\n\n----------\n👉🏼 Method: IG_SetZoom","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs","lineNumber":1202,"sourceCode":"        });\n\n        if (result.ExitCode != DialogExitCode.OK) return;\n\n        if (float.TryParse(result.InputValue.Trim(), out var newZoom))\n        {\n            Viewer.ZoomFactor = newZoom / 100f;\n        }\n    }\n\n\n    /// <summary>\n    /// Zoom to the current cursor location by the given factor.\n    /// </summary>\n    public void IG_SetZoom(string? factorStr)\n    {\n        if (!float.TryParse(factorStr, out var factor))\n        {\n            throw new ArgumentException($\"\"\"\n                Zoom factor '{factorStr}' is not a valid float.\n\n                ----------\n                👉🏼 Method: {nameof(IG_SetZoom)}\n                \"\"\",\n                nameof(factorStr));\n        }\n\n        IG_SetZoom(factor);\n    }\n\n    /// <summary>\n    /// Zoom to the current cursor location by the given factor.\n    /// </summary>\n    public static void IG_SetZoom(float factor)\n    {\n        _ = Viewer.ZoomToPoint(factor);\n    }","sourceCodeStart":1184,"sourceCodeEnd":1220,"githubUrl":"https://github.com/d2phap/ImageGlass/blob/4a3c4feceffc5a8bb5e56ba836509634aaae47a9/source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs#L1184-L1220","documentation":"Thrown by the string overload of IG_SetZoom when float.TryParse(factorStr) fails. The parse is culture-sensitive (no InvariantCulture supplied), so the accepted decimal separator depends on the current culture. A null, empty, or non-numeric string raises ArgumentException.","triggerScenarios":"Calling IG_SetZoom(string) with '1.5' in a comma-decimal locale (e.g., de-DE) where '.' is not accepted; '150%' with the percent sign; '' ; 'zoom'; a value with a thousands separator.","commonSituations":"Hard-coded '1.5' from an English-locale config breaks when the app runs under a European locale; user input copied with a percent sign; CLI argument with surrounding quotes/spaces.","solutions":["Pass a plain numeric string matching the current culture's decimal separator, or normalize to the current culture before calling.","Validate with float.TryParse (same overload the method uses) before invoking, and call the float overload directly.","Strip '%', spaces, and quotes upstream before parsing."],"exampleFix":"// before\napi.IG_SetZoom(userInput);\n\n// after\nvar cleaned = userInput?.Trim().TrimEnd('%');\nif (float.TryParse(cleaned, out var factor))\n{\n    api.IG_SetZoom(factor);\n}","handlingStrategy":"validation","validationCode":"var cleaned = factorStr?.Trim().TrimEnd('%');\nif (!float.TryParse(cleaned, out var factor))\n    throw new ArgumentException(\"Zoom factor must be numeric.\");\napi.IG_SetZoom(factor);","typeGuard":"static bool IsValidZoomFactor(string? s, IFormatProvider? p = null)\n    => float.TryParse(s?.Trim().TrimEnd('%'), out _);","tryCatchPattern":"try { api.IG_SetZoom(factorStr); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(factorStr))\n{ /* reject; note culture may be the cause */ }","preventionTips":["Strip '%', spaces, and quotes before parsing.","Remember the parse is culture-sensitive; match the user locale's decimal separator.","Validate with the same float.TryParse overload upstream."],"tags":["app-api","zoom","argument-parsing","float","i18n"],"backgroundTag":null,"analyzedSha":"4a3c4feceffc5a8bb5e56ba836509634aaae47a9","analyzedAt":"2026-08-13T16:58:15.523Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}