{"record":{"id":"b5b04ef71fa953dd","repo":"iOfficeAI/OfficeCLI","slug":"invalid-font-size-value-font-size-must-be-gr","errorCode":null,"errorMessage":"Invalid font size: '{value}'. Font size must be greater than 0.","messagePattern":"Invalid font size: '(.+?)'\\. Font size must be greater than 0\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/ParseHelpers.cs","lineNumber":369,"sourceCode":"        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    }\n\n    /// <summary>","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/ParseHelpers.cs#L351-L387","documentation":"Thrown by ParseFontSize when the parsed number is <= 0. A non-positive font size is invalid, so it is rejected before any OOXML write. This guard sits below the finite-number check and above the half-point minimum check.","triggerScenarios":"Passing \"0\", \"-5\", or a size computed as zero (e.g. baseSize - offset where offset >= baseSize).","commonSituations":"Font-size scaling math that bottoms out at zero; negative sizes from an inverted scale factor; default-unset sentinel of 0 leaking into the size field.","solutions":["Ensure the size is strictly positive (>0).","Clamp computed sizes to a small positive floor before parsing.","Treat 0 as 'unset/inherit' upstream rather than passing it to ParseFontSize."],"exampleFix":"// before\nvar size = (baseSize * scale).ToString(CultureInfo.InvariantCulture); // scale 0 -> 0\nParseFontSize(size); // throws 294\n\n// after\nvar pts = Math.Max(baseSize * scale, 1.0);\nParseFontSize(pts.ToString(CultureInfo.InvariantCulture));","handlingStrategy":"validation","validationCode":"if (pts <= 0) throw new InvalidOperationException(\"font size must be > 0\");\n// or clamp: pts = Math.Max(pts, 1.0);","typeGuard":"static bool IsPositiveSize(double v) => v > 0 && !double.IsNaN(v) && !double.IsInfinity(v);","tryCatchPattern":"try { pts = ParseFontSize(s); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"greater than 0\"))\n{ pts = 1; }","preventionTips":["Treat 0 as 'unset' upstream, never pass it to ParseFontSize.","Clamp scale-factor results to a positive floor.","Audit size math for underflow to zero."],"tags":["font","validation","argument","range"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}