{"record":{"id":"039a7c4ba9c5fe6d","repo":"iOfficeAI/OfficeCLI","slug":"invalid-margin-empty-value","errorCode":null,"errorMessage":"Invalid margin: empty value.","messagePattern":"Invalid margin: empty value\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.cs","lineNumber":68,"sourceCode":"            if (r1 > r2) (r1, r2) = (r2, r1);\n            if (r2 - r1 + 1 > 1024)\n                throw new ArgumentException(\n                    $\"Row span {cellRef} covers {r2 - r1 + 1} rows (limit 1024). Narrow the span or address rows individually as row[N].\");\n            var rows = new List<string>();\n            for (var i = r1; i <= r2; i++) rows.Add($\"row[{i}]\");\n            return rows;\n        }\n        return null;\n    }\n\n    /// <summary>\n    /// Parse a print-margin value into inches (PageMargins schema unit).\n    /// Accepts \"1in\", \"2.5cm\", \"1.27cm\", \"72pt\", \"10mm\", or a bare number (inches).\n    /// </summary>\n    internal static double ParseMarginInches(string value)\n    {\n        if (string.IsNullOrWhiteSpace(value))\n            throw new ArgumentException(\"Invalid margin: empty value.\");\n        var v = value.Trim().ToLowerInvariant();\n        double num;\n        if (v.EndsWith(\"in\"))\n        {\n            num = double.Parse(v[..^2].Trim(), System.Globalization.CultureInfo.InvariantCulture);\n            return num;\n        }\n        if (v.EndsWith(\"cm\"))\n        {\n            num = double.Parse(v[..^2].Trim(), System.Globalization.CultureInfo.InvariantCulture);\n            return num / 2.54;\n        }\n        if (v.EndsWith(\"mm\"))\n        {\n            num = double.Parse(v[..^2].Trim(), System.Globalization.CultureInfo.InvariantCulture);\n            return num / 25.4;\n        }\n        if (v.EndsWith(\"pt\"))","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.cs#L50-L86","documentation":"A print-margin value passed to ParseMarginInches was null, empty, or whitespace. PageMargins are stored in inches in the OOXML schema, so the parser needs a non-empty value to convert (it accepts '1in', '2.5cm', '72pt', '10mm', or a bare number in inches).","triggerScenarios":"Calling a page-margin setter with string.Empty, \"   \", or null. The string.IsNullOrWhiteSpace guard throws before any unit parsing.","commonSituations":"An optional config field omitted but still forwarded to the setter; a profile/template with a blank margin; UI field left empty and not filtered.","solutions":["Provide a value: a bare number (inches) or a unit-suffixed string ('1in', '2.5cm', '72pt', '10mm').","Skip the setter entirely when the margin field is unset, so Excel's default applies.","Validate non-empty at the config boundary."],"exampleFix":"// before\nws.PageMargins.Left = ParseMarginInches(marginCfg.Left);   // marginCfg.Left == \"\"\n\n// after\nif (!string.IsNullOrWhiteSpace(marginCfg.Left))\n    ws.PageMargins.Left = ParseMarginInches(marginCfg.Left);","handlingStrategy":"validation","validationCode":"static double? TryParseMarginInches(string? value) =>\n    string.IsNullOrWhiteSpace(value) ? (double?)null : ParseMarginInches(value);","typeGuard":null,"tryCatchPattern":"try { ws.PageMargins.Left = ParseMarginInches(raw); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"empty value\")) {\n    // leave Excel's default margin in place\n}","preventionTips":["Skip the margin setter when the config field is unset; do not forward blanks.","Validate margin strings at the config boundary, not at the OOXML writer."],"tags":["excel","page-setup","margin","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}