iOfficeAI/OfficeCLI · error · ArgumentException

Invalid 'height' value: '{value}'. Expected a finite number

Error message

Invalid 'height' value: '{value}'. Expected a finite number (row height in points, e.g. 15.75).

What it means

Thrown by ParseRowHeightPoints when the bare-number branch parsed the input successfully via double.TryParse but the result is NaN or Infinity. double.TryParse accepts 'NaN', 'Infinity', and '-Infinity' under NumberStyles.Float, so this guard explicitly rejects those non-finite sentinel strings before they would corrupt a row height.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Helpers.cs:137

            _ => null
        };

    // CONSISTENCY(rc-units): Row height is in points in OOXML; this helper
    // accepts bare numbers (treated as points, backward compat) as well as
    // unit-qualified "40pt", "40px", "1cm", "0.5in" and returns points.
    internal static double ParseRowHeightPoints(string value)
    {
        if (string.IsNullOrWhiteSpace(value))
            throw new ArgumentException("Row height cannot be empty.");
        var trimmed = value.Trim();
        double pts;
        // Bare number → points (legacy behavior)
        if (double.TryParse(trimmed, System.Globalization.NumberStyles.Float,
                System.Globalization.CultureInfo.InvariantCulture, out var bare)
            && !char.IsLetter(trimmed[^1]))
        {
            if (double.IsNaN(bare) || double.IsInfinity(bare))
                throw new ArgumentException($"Invalid 'height' value: '{value}'. Expected a finite number (row height in points, e.g. 15.75).");
            pts = bare;
        }
        else
        {
            // Unit-qualified: convert via EMU then back to points.
            try
            {
                var emu = OfficeCli.Core.EmuConverter.ParseEmu(trimmed);
                pts = emu / EmuConverter.EmuPerPointF;
            }
            catch (Exception ex)
            {
                throw new ArgumentException($"Invalid 'height' value: '{value}'. Expected a finite number or unit-qualified value (e.g. 15.75, 40pt, 40px, 1cm, 0.5in).", ex);
            }
        }
        // DEFERRED(xlsx/row-height-validation) RC2: Excel row height is bounded
        // [0, 409.5] points. Values outside this range are rejected by Excel at
        // open time (file silently repaired), so validate at Set time.

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Replace the non-finite value with a concrete finite number (e.g. 15.75 points).
  2. Fix the upstream arithmetic that produced NaN/Infinity (divide-by-zero, overflow) before passing it to the Set path.
  3. Validate with double.IsFinite before constructing the prop value.

Example fix

// before
var h = total / count;            // count == 0 -> NaN
set $"/Sheet1/row[5] --prop height={h}";

// after
var h = count == 0 ? 15.0 : total / count;
set $"/Sheet1/row[5] --prop height={h}";
Defensive patterns

Strategy: validation

Validate before calling

if (!double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var d) || !double.IsFinite(d))
    throw new ArgumentException($"Row height must be a finite number, got '{value}'.");

Prevention

When it happens

Trigger: Passing height=NaN, height=Infinity, height=-Infinity, or any string that double.TryParse accepts as non-finite (e.g. some locales yield '∞' through upstream transformation).

Common situations: A computation upstream divides by zero and the resulting NaN/Infinity is interpolated into the prop string; an LLM emits 'Infinity' as a placeholder; serialization of a default(double)/NaN field.

Related errors


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