{"record":{"id":"df2b2b22c7745764","repo":"iOfficeAI/OfficeCLI","slug":"invalid-linespacing-value-raw-line-spacing","errorCode":null,"errorMessage":"Invalid 'lineSpacing' value '{raw}'. Line spacing must be greater than 0.","messagePattern":"Invalid 'lineSpacing' value '(.+?)'\\. Line spacing must be greater than 0\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/SpacingConverter.cs","lineNumber":148,"sourceCode":"\n    /// <summary>\n    /// Parse line spacing for Word. Returns (twips, isMultiplier).\n    /// \"1.5x\" or \"150%\" → (360, true)  — Auto rule, 240 × multiplier\n    /// \"18pt\"           → (360, true=false) — Exact rule, pt × 20\n    /// \"0.5cm\"          → converted to pt, then Exact\n    /// bare number      → (number, true) — Auto rule, backward compat (raw twips)\n    /// </summary>\n    public static (int Twips, bool IsMultiplier) ParseWordLineSpacing(string value)\n    {\n        var trimmed = value.Trim();\n\n        // BUG-R7-04: lineSpacing must not be zero. Zero produces degenerate\n        // OOXML (w:spacing/@line=0 is undefined in MS-DOC) and Office silently\n        // collapses to single-spacing — surface the error to the user instead.\n        static double RequirePositive(double n, string raw)\n        {\n            if (n <= 0)\n                throw new ArgumentException($\"Invalid 'lineSpacing' value '{raw}'. Line spacing must be greater than 0.\");\n            return n;\n        }\n\n        // Auto/multiplier line spacing maps to w:line, which is\n        // ST_SignedTwipsMeasure — negatives are schema-legal and real docs\n        // carry them (e.g. <w:spacing w:line=\"-310\" w:lineRule=\"auto\"/> in a\n        // style). Reject only zero (degenerate per BUG-R7-04); allow negative\n        // so such styles round-trip instead of failing the whole add op.\n        static double RequireNonZero(double n, string raw)\n        {\n            if (n == 0)\n                throw new ArgumentException($\"Invalid 'lineSpacing' value '{raw}'. Line spacing must not be zero.\");\n            return n;\n        }\n\n        // \"1.5x\" → multiplier (negative permitted under the Auto rule)\n        if (trimmed.EndsWith(\"x\", StringComparison.OrdinalIgnoreCase))\n        {","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/SpacingConverter.cs#L130-L166","documentation":"Thrown by the RequirePositive local in ParseWordLineSpacing (BUG-R7-04) when a fixed (Exact) line-spacing value in cm or in units is <= 0. Zero produces degenerate OOXML (w:spacing/@line=0 is undefined in MS-DOC) and Office silently collapses to single-spacing, so it is surfaced. Used for the cm/in fixed paths. ArgumentException.","triggerScenarios":"Passing '0cm', '-1cm', '0in', or '-0.5in' as a Word lineSpacing (the fixed cm/in branches call RequirePositive). The pt branch has its own negative-only check and the multiplier branches use RequireNonZero.","commonSituations":"A user tries to set zero fixed line spacing to mean 'no spacing', or copies a negative value; a script passes 0 expecting single-line behavior.","solutions":["For single spacing use a multiplier: '1x' or '100%', not a zero fixed length.","For a small fixed line height use a positive value like '12pt'.","If you need a zero-exact/atLeast pair, note Word's '0pt' atLeast is allowed only via the pt branch (see error 419 context), not via cm/in."],"exampleFix":"// before\nset paragraph lineSpacing=0cm\n// after\nset paragraph lineSpacing=1x","handlingStrategy":"validation","validationCode":"var pts = SpacingConverter.ParsePoints(value);\nif (pts <= 0) throw new ArgumentException($\"lineSpacing must be > 0 for cm/in fixed: {value}\");\n// Use '1x'/'100%' for single spacing instead of a zero fixed length.","typeGuard":null,"tryCatchPattern":"try { var (tw, mult) = SpacingConverter.ParseWordLineSpacing(value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"greater than 0\"))\n{ /* use a positive fixed length or a multiplier like 1x */ }","preventionTips":["Use multiplier form ('1x') for single-line spacing, not zero fixed length.","Avoid 0cm/0in for lineSpacing.","Remember the pt branch allows 0 (for atLeast) but cm/in do not."],"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"}