{"record":{"id":"d94ed3dd8d012074","repo":"iOfficeAI/OfficeCLI","slug":"invalid-font-size-value-expected-a-finite-nu","errorCode":null,"errorMessage":"Invalid font size: '{value}'. Expected a finite number (e.g., '12', '10.5', '14pt').","messagePattern":"Invalid font size: '(.+?)'\\. Expected a finite number \\(e\\.g\\., '12', '10\\.5', '14pt'\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/ParseHelpers.cs","lineNumber":367,"sourceCode":"    /// </summary>\n    public static bool IsValidBooleanString(string? value) =>\n        value != null && TrimInvisible(value).ToLowerInvariant() is \"true\" or \"1\" or \"yes\" or \"on\"\n                                                                 or \"false\" or \"0\" or \"no\" or \"off\";\n\n    /// <summary>\n    /// Parse a font size string, stripping optional \"pt\" suffix.\n    /// Supports integers and fractional values (e.g. \"24\", \"10.5\", \"24pt\").\n    /// Returns double to preserve fractional sizes for correct unit conversion.\n    /// </summary>\n    public static double ParseFontSize(string value)\n    {\n        var trimmed = value.Trim();\n        if (trimmed.EndsWith(\"pt\", StringComparison.OrdinalIgnoreCase))\n            trimmed = trimmed[..^2].Trim();\n        if (trimmed.Contains(','))\n            throw new ArgumentException($\"Invalid font size: '{value}'. Comma is not allowed — use '.' as decimal separator (e.g., '10.5').\");\n        if (!double.TryParse(trimmed, CultureInfo.InvariantCulture, out var result) || double.IsNaN(result) || double.IsInfinity(result))\n            throw new ArgumentException($\"Invalid font size: '{value}'. Expected a finite number (e.g., '12', '10.5', '14pt').\");\n        if (result <= 0)\n            throw new ArgumentException($\"Invalid font size: '{value}'. Font size must be greater than 0.\");\n        // OOXML w:sz/w:szCs/w:fontSize are half-points and must be >= 1.\n        // Anything below 0.5pt would round to val=0 on write, producing\n        // schema-invalid OOXML. Reject up front with the same shape as\n        // the \"<= 0\" guard above.\n        if (result < 0.5)\n            throw new ArgumentException($\"Invalid font size: '{value}'. Minimum font size is 0.5pt (one half-point).\");\n        // OOXML caps user-entered font size at 1638pt (Word) and Office\n        // renderers stop honoring values past ~4000pt anyway. Anything\n        // larger silently overflows the int32 the writers cast to (PPTX\n        // writes pt × 100, Word writes pt × 2 as half-points), producing\n        // negative w:sz / a:rPr@sz values Word rejects on open. Reject\n        // up front with the same shape as the lower-bound guards.\n        if (result > 4000)\n            throw new ArgumentException($\"Invalid font size: '{value}'. Maximum font size is 4000pt (Office cap).\");\n        return result;\n    }","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/ParseHelpers.cs#L349-L385","documentation":"Thrown by ParseFontSize when, after stripping an optional 'pt' suffix, the token is not a finite parseable number. This catches non-numeric sizes, NaN, and infinity. The 'pt' suffix is allowed but everything else must be a plain number.","triggerScenarios":"Passing \"abc\", \"\", \"12px\" (px is not a recognized unit), or \"1e999\" (overflow to infinity). Also a size field that was never set and defaulted to an empty/placeholder string.","commonSituations":"Unit mismatch (px/em instead of pt or bare number); a JSON config with a null/empty size that got stringified; a template placeholder left in place.","solutions":["Supply a plain number or number+'pt' (e.g. \"12\" or \"12pt\").","Convert other units to points before calling (1px ≈ 0.75pt at 96dpi).","Validate the string is non-empty and numeric before parsing."],"exampleFix":"// before\nprops[\"fontSize\"] = \"12px\";\nParseFontSize(props[\"fontSize\"]); // throws 293\n\n// after\nprops[\"fontSize\"] = \"9\"; // 12px ≈ 9pt\nParseFontSize(props[\"fontSize\"]);","handlingStrategy":"validation","validationCode":"if (!double.TryParse(size.TrimEnd(\"ptsPT\".ToCharArray()), CultureInfo.InvariantCulture, out _))\n    size = \"12\";","typeGuard":"static bool IsParsableSize(string s)\n{ var t = s.Trim(); if (t.EndsWith(\"pt\", StringComparison.OrdinalIgnoreCase)) t = t[..^2].Trim();\n  return double.TryParse(t, CultureInfo.InvariantCulture, out var d) && !double.IsNaN(d) && !double.IsInfinity(d); }","tryCatchPattern":"try { pts = ParseFontSize(s); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"finite number\"))\n{ pts = 12; }","preventionTips":["Supply plain numbers or number+'pt'.","Convert px/em to points before formatting.","Validate the field is non-empty before parsing."],"tags":["font","validation","argument","number-format"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}