iOfficeAI/OfficeCLI · error · ArgumentException

Unknown label position '{value}'. Valid: center, insideEnd,

Error message

Unknown label position '{value}'. Valid: center, insideEnd, outsideEnd, insideBase, top, bottom, left, right, bestFit.

What it means

Thrown by ParseDataLabelPosition (ChartHelper.SetterHelpers.cs:257) when a data-label position token, after ToLowerInvariant, matches none of center/ctr, insideend/inside/inend, outsideend/outside/outend, insidebase/inbase/base, top/t, bottom/b, left/l, right/r, bestfit/best. This is the single source of truth for labelPos alias parsing, covering both friendly aliases and raw schema tokens the Reader emits verbatim so dump-to-replay always works. Unknown tokens throw rather than silently coerce to OutsideEnd (the old silent-accept enum-miss family).

Source

Thrown at src/officecli/Core/Chart/ChartHelper.SetterHelpers.cs:257

    // friendly alias plus the raw schema tokens the Reader emits verbatim
    // (ctr, t, b, l, r, outEnd, inEnd, inBase, bestFit) so dump→batch replay
    // always parses. Unknown tokens throw instead of silently coercing to
    // OutsideEnd (silent-accept enum-miss family); the three former inline
    // switches each covered a different subset, so a token accepted on one
    // path could throw or coerce on another.
    internal static C.DataLabelPositionValues ParseDataLabelPosition(string value) =>
        value.ToLowerInvariant() switch
        {
            "center" or "ctr" => C.DataLabelPositionValues.Center,
            "insideend" or "inside" or "inend" => C.DataLabelPositionValues.InsideEnd,
            "outsideend" or "outside" or "outend" => C.DataLabelPositionValues.OutsideEnd,
            "insidebase" or "inbase" or "base" => C.DataLabelPositionValues.InsideBase,
            "top" or "t" => C.DataLabelPositionValues.Top,
            "bottom" or "b" => C.DataLabelPositionValues.Bottom,
            "left" or "l" => C.DataLabelPositionValues.Left,
            "right" or "r" => C.DataLabelPositionValues.Right,
            "bestfit" or "best" => C.DataLabelPositionValues.BestFit,
            _ => throw new ArgumentException(
                $"Unknown label position '{value}'. Valid: center, insideEnd, outsideEnd, insideBase, top, bottom, left, right, bestFit.")
        };

    internal static C.ErrorBars BuildErrorBars(string spec)
    {
        // Format: "type" or "type:value" e.g. "fixed:5", "percent:10", "stddev", "stderr"
        // R55 bt-6: cust spec is "cust:<direction>:<plusCSV>:<minusCSV>" — emit
        // per-direction <c:plus>/<c:minus> NumberLiteral arrays. The Reader
        // pairs with this form (ReadErrorBarSideCsv) so dump-replay of cust
        // error bars round-trips through the inline numLit cache, not numRef
        // (which would need a live cell reference on the embedded workbook).
        // CONSISTENCY(errorbars-bare-number): bare number (e.g. "5") is taken as
        // fixed:<N>, mirroring how other chart numeric specs accept a value-only
        // shorthand. Without this, "5" matched no type-name arm and fell through
        // to FixedValue with no magnitude — producing zero-height error bars.
        var parts = spec.Split(':');
        var typeStr = parts[0].Trim().ToLowerInvariant();
        string? bareValue = null;

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use one of: center, insideEnd, outsideEnd, insideBase, top, bottom, left, right, bestFit (aliases: ctr, inside, inEnd, outside, outEnd, inBase, base, t, b, l, r, best).
  2. Check that the position is valid for the chart type — bestFit is pie/doughnut only, insideBase is bar/column only.

Example fix

// before
labelPos=above
// after
labelPos=top
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> LabelPositions = new(StringComparer.OrdinalIgnoreCase)
{ "center","ctr","insideend","inside","inend","outsideend","outside","outend","insidebase","inbase","base","top","t","bottom","b","left","l","right","r","bestfit","best" };
static string ValidateLabelPosition(string v) => LabelPositions.Contains((v ?? "").Trim().ToLowerInvariant()) ? v : throw new ArgumentException($"unknown label position '{v}'");

Type guard

static bool IsValidLabelPosition(string v) => LabelPositions.Contains((v ?? "").Trim().ToLowerInvariant());

Try / catch

try { /* set chart labelPos=... */ }
catch (ArgumentException ex) when (ex.Message.Contains("Unknown label position"))
{ /* list valid positions for the chart type */ }

Prevention

When it happens

Trigger: Setting labelPos / dataLabelPosition to an unrecognized token, e.g. 'outside-base', 'auto', 'middle', 'above', 'centered', or a chart-type-specific position that does not exist in the OOXML enum.

Common situations: Using a position valid for one chart type on another (e.g. 'bestFit' is pie-only); guessing 'above'/'below' instead of top/bottom; copying an Excel-internal enum name that is not aliased here.

Related errors


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