iOfficeAI/OfficeCLI · warning · ArgumentException

Invalid 'reflection' value '{value}'. Valid presets: none, t

Error message

Invalid 'reflection' value '{value}'. Valid presets: none, tight, small, half, true, full; or a numeric percentage 0-100.

What it means

BuildReflection parses the reflection value: named presets (tight/small=true/half/full, plus implicit none) map to fixed endPos values; anything else must be an integer percentage 0..100. An unrecognized preset AND a non-integer/out-of-range number is rejected, so a typo no longer silently falls back to 'half'.

Source

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

    /// <summary>
    /// Build a Reflection element from a value string.
    /// Values: "tight"/"small", "half"/"true", "full", or numeric percentage.
    /// </summary>
    public static Drawing.Reflection BuildReflection(string value)
    {
        // Unknown preset names (and out-of-range numerics) used to silently
        // fall back to "half" (90000), masking typos. Reject so the caller
        // surfaces the value rather than writing a no-op effect.
        int endPos;
        switch (value.ToLowerInvariant())
        {
            case "tight": case "small": endPos = 55000; break;
            case "true":  case "half":  endPos = 90000; break;
            case "full":               endPos = 100000; break;
            default:
                if (!int.TryParse(value, out var pct) || pct < 0 || pct > 100)
                    throw new ArgumentException(
                        $"Invalid 'reflection' value '{value}'. Valid presets: none, tight, small, half, true, full; or a numeric percentage 0-100.");
                endPos = (int)Math.Min((long)pct * 1000, 100000);
                break;
        }

        return new Drawing.Reflection
        {
            BlurRadius = 6350,
            StartOpacity = 52000,
            StartPosition = 0,
            EndAlpha = 300,
            EndPosition = endPos,
            Distance = 0,
            Direction = 5400000,
            VerticalRatio = -100000,
            Alignment = Drawing.RectangleAlignmentValues.BottomLeft,
            RotateWithShape = false
        };

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use a documented preset: none, tight, small, half (or true), full.
  2. Or use an integer percentage 0..100.
  3. Check spelling and remove stray suffixes/units.

Example fix

// before — typo / out of range
effect="reflection:mediuM"
effect="reflection:150"

// after
effect="reflection:medium"   // still invalid — use a preset:
effect="reflection:half"
effect="reflection:50"
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> ReflectionPresets = new(StringComparer.OrdinalIgnoreCase)
    { "none","tight","small","half","true","full" };
static bool IsValidReflection(string v)
    => ReflectionPresets.Contains(v) || (int.TryParse(v, out var p) && p is >= 0 and <= 100);

Try / catch

try { DrawingEffectsHelper.BuildReflection(value); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid 'reflection'", StringComparison.Ordinal))
{ errors.Add(ex.Message); }

Prevention

When it happens

Trigger: A reflection value that is neither a known preset nor a valid percentage: 'refelct' (typo), 'medium', 'half-full', '150' (>100), '-5' (<0), 'abc'.

Common situations: Typo in a preset name; using a word the UI shows but this API doesn't accept; a percentage outside 0..100; a locale-specific decimal separator ('50,5').

Related errors


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