iOfficeAI/OfficeCLI · error · ArgumentException

Invalid spacing value '{value}'. Value too large — exceeds m

Error message

Invalid spacing value '{value}'. Value too large — exceeds maximum representable spacing (~{int.MaxValue / 100.0}pt).

What it means

Thrown by ParsePptSpacing (BUG-R7-03) when the value, converted to hundredths of a point, exceeds int.MaxValue. CT_TextSpacing stores hundredths in a 32-bit signed int (~21,474,836.47pt max). Without this guard a huge value silently overflowed/clamped on cast, producing a wrong readback. ArgumentException naming the approximate maximum.

Source

Thrown at src/officecli/Core/SpacingConverter.cs:98

    //  spaceBefore / spaceAfter  →  PPT hundredths-of-a-point
    // ────────────────────────────────────────────────────────────────

    /// <summary>
    /// Parse a spacing value (spaceBefore/spaceAfter) to PPT hundredths-of-a-point (int).
    /// Accepts: "12pt", "0.5cm", "0.5in", or bare number (treated as points for backward compat).
    /// </summary>
    public static int ParsePptSpacing(string value)
    {
        var points = ParseSpacingToPoints(value, bareIsPoints: true);
        if (points < 0)
            throw new ArgumentException($"Invalid spacing value '{value}'. Spacing must be non-negative.");
        // BUG-R7-03: PPT stores spaceBefore/spaceAfter in hundredths of a point
        // as a 32-bit signed integer (CT_TextSpacing). Compute in 64-bit and
        // reject values that would silently overflow on cast — the symptom was
        // 999999999pt clamping to int.MaxValue/100 ≈ 21474836.47pt readback.
        var hundredths = (long)Math.Round(points * 100);
        if (hundredths > int.MaxValue)
            throw new ArgumentException(
                $"Invalid spacing value '{value}'. Value too large — exceeds maximum representable spacing (~{int.MaxValue / 100.0}pt).");
        return (int)hundredths;
    }

    /// <summary>
    /// Parse a length value to points, allowing negative values. Accepts
    /// unit-qualified "12pt", "0.5cm", "0.5in", "-1cm", "-12pt", or a bare
    /// signed number (treated as points). Used for PPTX paragraph indent
    /// which permits hanging-indent style negatives. CONSISTENCY(pptx-bare-as-points).
    /// </summary>
    public static double ParsePointsSigned(string value)
    {
        return ParseSpacingToPointsSigned(value, bareIsPoints: true);
    }

    /// <summary>
    /// Parse a length value to points. Accepts unit-qualified "12pt", "0.5cm",
    /// "0.5in" or bare number (treated as points). Used for XLSX shape margin

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use a physically reasonable spacing value (PPT paragraphs rarely exceed a few hundred points).
  2. Check the units — ensure you are passing points/cm/in, not an inflated raw integer.
  3. Validate the value is under ~21,474,836pt before calling.

Example fix

// before
set shape text spacing spaceBefore=999999999pt
// after
set shape text spacing spaceBefore=12pt
Defensive patterns

Strategy: validation

Validate before calling

const double MaxPptPt = int.MaxValue / 100.0; // ~21,474,836.47pt
var pts = SpacingConverter.ParsePoints(value);
if (pts > MaxPptPt) throw new ArgumentException($"Value too large for PPT spacing: {value}");

Try / catch

try { var hundredths = SpacingConverter.ParsePptSpacing(value); }
catch (ArgumentException ex) when (ex.Message.Contains("Value too large"))
{ /* clamp/repair the source value; check unit confusion */ }

Prevention

When it happens

Trigger: Passing an astronomically large spacing value such as '999999999pt' or '50000000pt' to a PPT spacing slot. Computation is done in 64-bit then compared to int.MaxValue.

Common situations: A script bug feeds an unchecked or unit-confused number (e.g. twips passed where points expected, magnifying the value), or a copied large table cell-spacing value is applied to paragraph spacing.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/893a85b6309f9663. Report an issue: GitHub.