iOfficeAI/OfficeCLI · error · ArgumentException

Unknown errorStyle: {dvErrStyle}. Use: stop, warning, inform

Error message

Unknown errorStyle: {dvErrStyle}. Use: stop, warning, information

What it means

Thrown by AddValidation when the optional "errorStyle" property is present but its lower-cased value is not stop, warning (or warn), or information (or info). These map to DataValidationErrorStyleValues; an unrecognized style is rejected rather than silently defaulting to stop.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs:656

        if (properties.TryGetValue("errorTitle", out var dvErrorTitle))
            dv.ErrorTitle = dvErrorTitle;
        if (properties.TryGetValue("error", out var dvError))
            dv.Error = dvError;
        if (properties.TryGetValue("promptTitle", out var dvPromptTitle))
            dv.PromptTitle = dvPromptTitle;
        if (properties.TryGetValue("prompt", out var dvPrompt))
            dv.Prompt = dvPrompt;

        // V6 — errorStyle: stop (default), warning, information.
        if (properties.TryGetValue("errorStyle", out var dvErrStyle))
        {
            dv.ErrorStyle = dvErrStyle.ToLowerInvariant() switch
            {
                "stop" => DataValidationErrorStyleValues.Stop,
                "warning" or "warn" => DataValidationErrorStyleValues.Warning,
                "information" or "info" => DataValidationErrorStyleValues.Information,
                _ => throw new ArgumentException(
                    $"Unknown errorStyle: {dvErrStyle}. Use: stop, warning, information")
            };
        }

        // V7 — showDropDown / inCellDropdown. OOXML `showDropDown`
        // has INVERTED semantics: true = HIDE the in-cell arrow.
        // Expose it as `inCellDropdown` (user-friendly sense) and
        // the raw `showDropDown` (OOXML sense).
        if (properties.TryGetValue("inCellDropdown", out var dvInCell))
            dv.ShowDropDown = !ParseHelpers.IsTruthy(dvInCell);
        else if (properties.TryGetValue("showDropDown", out var dvShowDd))
            dv.ShowDropDown = ParseHelpers.IsTruthy(dvShowDd);

        var wsEl = GetSheet(dvWorksheet);
        var dvs = wsEl.GetFirstChild<DataValidations>();
        // R27-3: stacking a second DV on a sqref that overlaps an existing
        // DV is silently invisible in Excel (first wins). Reject up-front
        // rather than persist a useless rule.

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use one of: stop, warning, information (warn/info aliases accepted).
  2. Omit errorStyle entirely to keep the Excel default (stop).
  3. Validate the value against the allowed set before calling.

Example fix

// before
handler.Add("/Sheet1", "validation", null,
    new() { ["sqref"] = "A1:A5", ["type"] = "whole", ["errorStyle"] = "critical" });
// after
handler.Add("/Sheet1", "validation", null,
    new() { ["sqref"] = "A1:A5", ["type"] = "whole", ["errorStyle"] = "stop" });
Defensive patterns

Strategy: type-guard

Validate before calling

static readonly HashSet<string> ErrStyles = new(StringComparer.OrdinalIgnoreCase)
    { "stop", "warning", "warn", "information", "info" };
if (properties.TryGetValue("errorStyle", out var es) && !ErrStyles.Contains(es))
    throw new ArgumentOutOfRangeException($"bad errorStyle '{es}'");

Type guard

static bool IsValidErrorStyle(string? es) =>
    es is not null && (new[] { "stop", "warning", "warn", "information", "info" })
        .Contains(es, StringComparer.OrdinalIgnoreCase);

Prevention

When it happens

Trigger: Call Add type "validation" with properties["errorStyle"] set to an out-of-set value (e.g. "critical", "error", "mandatory", "hard").

Common situations: Using the Excel-UI word 'Stop' as something else; expecting 'error' as a synonym for 'stop'; typos; mixing alert-style vocabulary from another library.

Related errors


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