{"record":{"id":"19dfa4b896d01f02","repo":"iOfficeAI/OfficeCLI","slug":"invalid-linespacing-value-value-line-spacin","errorCode":null,"errorMessage":"Invalid 'lineSpacing' value '{value}'. Line spacing must not be negative.","messagePattern":"Invalid 'lineSpacing' value '(.+?)'\\. Line spacing must not be negative\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/SpacingConverter.cs","lineNumber":187,"sourceCode":"        }\n\n        // \"150%\" → multiplier (negative permitted under the Auto rule)\n        if (trimmed.EndsWith(\"%\", StringComparison.Ordinal))\n        {\n            var num = RequireNonZero(ParseNumberAllowNegative(trimmed[..^1], \"lineSpacing\"), value);\n            return ((int)Math.Round(num / 100.0 * WordAutoLineSpacingUnit), true);\n        }\n\n        // \"18pt\" → fixed (Exact). \"0pt\" is allowed: paired with\n        // lineRule=atLeast it round-trips Word's <w:spacing w:line=\"0\"\n        // w:lineRule=\"atLeast\"/> (\"no minimum line height\") — dropping it\n        // re-rendered those paragraphs at the style's default line height\n        // and reflowed the page. Negative still rejected.\n        if (trimmed.EndsWith(\"pt\", StringComparison.OrdinalIgnoreCase))\n        {\n            var num = ParseNumber(trimmed[..^2], \"lineSpacing\");\n            if (num < 0)\n                throw new ArgumentException($\"Invalid 'lineSpacing' value '{value}'. Line spacing must not be negative.\");\n            return ((int)Math.Round(num * TwipsPerPoint), false);\n        }\n\n        // \"0.5cm\" → fixed (Exact), convert to points first\n        if (trimmed.EndsWith(\"cm\", StringComparison.OrdinalIgnoreCase))\n        {\n            var num = RequirePositive(ParseNumber(trimmed[..^2], \"lineSpacing\"), value);\n            return ((int)Math.Round(num * PointsPerCm * TwipsPerPoint), false);\n        }\n\n        // \"0.5in\" → fixed (Exact)\n        if (trimmed.EndsWith(\"in\", StringComparison.OrdinalIgnoreCase))\n        {\n            var num = RequirePositive(ParseNumber(trimmed[..^2], \"lineSpacing\"), value);\n            return ((int)Math.Round(num * PointsPerInch * TwipsPerPoint), false);\n        }\n\n        // Bare number → multiplier under Auto rule, mirrors the \"1.5x\" path.","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/SpacingConverter.cs#L169-L205","documentation":"Thrown by the pt branch of ParseWordLineSpacing when a fixed (Exact) line-spacing value in points is negative. Note '0pt' is deliberately allowed because paired with lineRule=atLeast it round-trips Word's 'no minimum line height'; only negatives are rejected. The cm/in branches reject zero too via RequirePositive (see error 417). ArgumentException.","triggerScenarios":"Passing a negative point value such as '-18pt' as a fixed Word lineSpacing. The pt branch parses the number and checks num < 0.","commonSituations":"A negative value copied from an auto/multiplier context (where negatives are legal) into the fixed pt form, or a script bug producing a negative length.","solutions":["Use a non-negative point value (e.g. '18pt'); '0pt' is acceptable for atLeast round-tripping.","If you need a negative auto line spacing, use the multiplier form ('-1.5x') which permits negatives, not the fixed pt form.","Confirm the intended lineRule before choosing the value form."],"exampleFix":"// before\nset paragraph lineSpacing=-18pt\n// after\nset paragraph lineSpacing=18pt","handlingStrategy":"validation","validationCode":"var trimmed = value.Trim();\nif (trimmed.EndsWith(\"pt\", StringComparison.OrdinalIgnoreCase))\n{\n    var n = double.Parse(trimmed[..^2], CultureInfo.InvariantCulture);\n    if (n < 0) throw new ArgumentException(\"lineSpacing pt must not be negative\");\n}\nvar r = SpacingConverter.ParseWordLineSpacing(value);","typeGuard":null,"tryCatchPattern":"try { var (tw, mult) = SpacingConverter.ParseWordLineSpacing(value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"must not be negative\"))\n{ /* use a non-negative pt value; 0pt is allowed for atLeast */ }","preventionTips":["Use non-negative points for fixed Word lineSpacing; 0pt is allowed.","For negative auto line spacing, use the multiplier form ('-1.5x') not pt.","Confirm intended lineRule before choosing value form."],"tags":["spacing","word","line-spacing","argument","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}