iOfficeAI/OfficeCLI · warning · ArgumentException

Invalid {paramName} value: '{raw}'.

Error message

Invalid {paramName} value: '{raw}'.

What it means

ParseParam strips a trailing alpha/% unit suffix (pt/deg/%/cm/in/px/emu) from the token, then requires the remaining numeric part to parse as a finite double under invariant culture. If it doesn't (or is NaN/infinity), it throws with the raw token. The strip lets callers write '5pt'/'45deg'/'40%' for the native dimension, but other units are not converted.

Source

Thrown at src/officecli/Core/DrawingEffectsHelper.cs:356

        // dimension so callers can write "5pt", "45deg", "40%" without
        // forcing them to know the internal unit. Strip and parse the
        // numeric prefix; reject unknown trailing letters.
        var num = raw.Trim();
        if (num.Length == 0)
            throw new ArgumentException($"Invalid {paramName} value: '{raw}' (empty).");
        // Strip a trailing alpha unit suffix (pt/deg/%/cm/in/px/emu). The
        // numeric routes through pt/deg/% as-is — units other than pt for a
        // pt-dimension still parse the number but the result is not
        // converted; agents should stick to bare numbers or the native unit
        // for now. The point of this fix is to stop ParseParam throwing on
        // a unit-qualified token; a future pass can do real unit conversion.
        int suffixStart = num.Length;
        while (suffixStart > 0 && (char.IsLetter(num[suffixStart - 1]) || num[suffixStart - 1] == '%'))
            suffixStart--;
        var numPart = num[..suffixStart];
        if (!double.TryParse(numPart, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var val)
            || double.IsNaN(val) || double.IsInfinity(val))
            throw new ArgumentException($"Invalid {paramName} value: '{raw}'.");
        return val;
    }

    /// <summary>
    /// Split an effect value string into ["color", "p1", "p2", …] tokens.
    /// Historical separator is '-', but '-' collides with negative numbers
    /// (e.g. "red;-5" for a shadow with negative angle). Prefer ';' when
    /// present; fall back to '-' for the legacy form. Empty tokens are
    /// rejected up front so opacity/blur don't silently take the default
    /// for a malformed input like "red;;5".
    /// </summary>
    private static string[] SplitEffectParts(string value)
    {
        if (string.IsNullOrEmpty(value))
            throw new ArgumentException("Effect value cannot be empty.");
        // Prefer ';' so negative numeric params (e.g. "-5") survive split.
        // When ';' is present, treat '-' as part of a numeric value, not a
        // separator. Fall back to '-' for the legacy form. In ';' mode,

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use a '.' decimal separator and a clean numeric prefix.
  2. Ensure the token has digits before the optional unit suffix ('5pt', not 'pt').
  3. Only append a recognized suffix (pt/deg/%/cm/in/px/emu); unrecognized trailing letters become part of the failed parse.

Example fix

// before — comma decimal under invariant culture
effect="shadow:red;5,5;45"

// after — dot decimal
effect="shadow:red;5.5;45"
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidEffectParam(string token)
{
    var num = token.Trim();
    int s = num.Length;
    while (s > 0 && (char.IsLetter(num[s - 1]) || num[s - 1] == '%')) s--;
    var np = num[..s];
    return np.Length > 0
        && double.TryParse(np, NumberStyles.Float, CultureInfo.InvariantCulture, out var v)
        && !double.IsNaN(v) && !double.IsInfinity(v);
}

Try / catch

try { effect = DrawingEffectsHelper.Build(value); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid ", StringComparison.Ordinal) && ex.Message.Contains("value:", StringComparison.Ordinal))
{ errors.Add(ex.Message); }

Prevention

When it happens

Trigger: A token whose numeric prefix won't parse: 'abc', '5..5', 'pt' (suffix only, empty number), '5,5' (comma under invariant culture), or a value with an unrecognized leading symbol. numPart after stripping letters/% isn't a finite double.

Common situations: Locale decimal separator (comma) on a culture where invariant rejects it; a stray character in the number; only a unit suffix with no digits; double decimal points.

Related errors


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