{"record":{"id":"7e67f82fb93bf19e","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"font-size-must-be-higher-than-0","errorCode":null,"errorMessage":"Font size must be higher than 0","messagePattern":"Font size must be higher than 0","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"source/KlocTools/Subsystems/FontGrabber.cs","lineNumber":29,"sourceCode":"\nnamespace Klocman.Subsystems\n{\n    public sealed class FontGrabber\n    {\n        private readonly Dictionary<string, FontFamily> _validFontFamilies = new();\n\n        public FontGrabber()\n        {\n            UpdateFontFamilies();\n        }\n\n        public IEnumerable<FontFamily> ValidFontFamilies => _validFontFamilies.Values;\n        public IEnumerable<string> ValidFontFamilyNames => _validFontFamilies.Keys;\n\n        public Font GetFont(string familyName, float size, FontStyle style)\n        {\n            if (size <= 0)\n                throw new ArgumentException(\"Font size must be higher than 0\");\n\n            return _validFontFamilies.ContainsKey(familyName)\n                ? new Font(_validFontFamilies[familyName], size, style)\n                : null;\n        }\n\n        public FontFamily GetFontFamily(string familyName)\n        {\n            return _validFontFamilies.ContainsKey(familyName) ? _validFontFamilies[familyName] : null;\n            //throw new ArgumentException(\"Invalid font family name\");\n        }\n\n        private void UpdateFontFamilies()\n        {\n            using (var installedFonts = new InstalledFontCollection())\n            {\n                foreach (var t in installedFonts.Families.Where(t => t.IsStyleAvailable(FontStyle.Regular)))\n                {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/KlocTools/Subsystems/FontGrabber.cs#L11-L47","documentation":"Thrown by FontGrabber.GetFont(string familyName, float size, FontStyle style) when size <= 0. A non-positive em-size is invalid for System.Drawing.Font, so the method rejects it before constructing anything. Family-name validity is handled separately (returns null for unknown families).","triggerScenarios":"Calling GetFont with size 0, a negative size, or NaN/-Infinity (float). Common when the size is read from config or computed (e.g. baseSize * factor where factor is 0).","commonSituations":"Configurable font sizes defaulting to 0 when unset, DPI-scaling math producing 0 for very small factors, division-by-zero producing NaN, or passing an unset int/float setting straight through.","solutions":["Clamp the size to a positive minimum before calling: size = Math.Max(size, 1f);","Treat 0/negative as 'use default' and substitute a sensible default size.","Validate config-loaded font sizes at load time and reject non-positive values."],"exampleFix":"// before\nvar font = grabber.GetFont(name, userSize, style); // userSize may be 0\n\n// after\nvar font = grabber.GetFont(name, Math.Max(userSize, 8f), style);","handlingStrategy":"validation","validationCode":"size = float.IsNaN(size) || size <= 0 ? 8f : size;\nvar font = grabber.GetFont(familyName, size, style);","typeGuard":"static bool IsValidFontSize(float size) => !float.IsNaN(size) && !float.IsInfinity(size) && size > 0f;","tryCatchPattern":null,"preventionTips":["Clamp user-supplied sizes to a minimum at the config/UI boundary.","Guard DPI-scaling math against zero/negative factors.","Default unset font-size settings to a sensible non-zero value."],"tags":["drawing","validation","fonts","csharp","kloctools"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}