{"record":{"id":"449b6c0d5ff98b2c","repo":"iOfficeAI/OfficeCLI","slug":"invalid-labelpos-value-expected-one-of-ctr-i","errorCode":null,"errorMessage":"Invalid labelPos '{value}': expected one of ctr, inBase, inEnd, outEnd, t, b, l, r, bestFit.","messagePattern":"Invalid labelPos '(.+?)': expected one of ctr, inBase, inEnd, outEnd, t, b, l, r, bestFit\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/Chart/ChartHelper.Setter.cs","lineNumber":704,"sourceCode":"                            ? C.DataLabelPositionValues.Center\n                            : C.DataLabelPositionValues.BestFit,\n                        \"top\" or \"t\" => isStacked\n                            ? C.DataLabelPositionValues.InsideEnd\n                            : C.DataLabelPositionValues.Top,\n                        \"bottom\" or \"b\" => isStacked\n                            ? C.DataLabelPositionValues.InsideBase\n                            : C.DataLabelPositionValues.Bottom,\n                        \"left\" or \"l\" => isStacked\n                            ? C.DataLabelPositionValues.InsideEnd\n                            : C.DataLabelPositionValues.Left,\n                        \"right\" or \"r\" => isStacked\n                            ? C.DataLabelPositionValues.InsideEnd\n                            : C.DataLabelPositionValues.Right,\n                        // Schema enum: {ctr, inBase, inEnd, outEnd, t, b, l, r, bestFit}\n                        // plus the long-form aliases handled above. Anything else\n                        // is a typo or fuzz garbage — reject up front rather than\n                        // silently map to BestFit/OutsideEnd and bury the bug.\n                        _ => throw new ArgumentException(\n                            $\"Invalid labelPos '{value}': expected one of ctr, inBase, inEnd, outEnd, t, b, l, r, bestFit.\")\n                    };\n                    var existingLabels = plotArea2.Descendants<C.DataLabels>().ToList();\n                    if (existingLabels.Count == 0)\n                    {\n                        // Bootstrap charts often lack a c:dLbls element entirely.\n                        // Without one, labelPos has nowhere to land and Get sees\n                        // nothing — schema declares labelPos get:true so we must\n                        // materialize the parent. Attach to the first chart-group\n                        // (barChart/lineChart/pieChart/scatterChart/etc.).\n                        var chartGroup = plotArea2.ChildElements.OfType<OpenXmlCompositeElement>()\n                            .FirstOrDefault(e => e is C.BarChart or C.Bar3DChart\n                                or C.LineChart or C.Line3DChart or C.PieChart or C.Pie3DChart\n                                or C.ScatterChart or C.BubbleChart);\n                        if (chartGroup != null)\n                        {\n                            var dLbls = new C.DataLabels();\n                            // c:dLbls schema requires showLegendKey..showBubbleSize","sourceCodeStart":686,"sourceCodeEnd":722,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/Chart/ChartHelper.Setter.cs#L686-L722","documentation":"Thrown when 'labelPos' on a non-pie chart does not match any switch arm of the position parser. The schema enum ST_DLblPos is {ctr, inBase, inEnd, outEnd, t, b, l, r, bestFit} plus long-form aliases (center, insideEnd, etc.). Anything else is treated as a typo or fuzz garbage and rejected rather than silently mapped to a default.","triggerScenarios":"SetChartProperties with { [\"labelPos\"] = \"outer\" }, \"middel\", \"insideEnd \" (trailing space is not trimmed for this key), or any token not in the accepted alias set.","commonSituations":"Free-text label position from a UI textbox; whitespace/case mismatch (only lowercase is matched); values copied from a non-Excel charting library (e.g. 'outer', 'middle').","solutions":["Use one of the accepted spellings: ctr/center, inBase/insideBase/base, inEnd/insideEnd/inside, outEnd/outsideEnd/outside, t/top, b/bottom, l/left, r/right, bestFit/best/auto.","Trim and ToLowerInvariant the user input before passing it in.","Whitelist labelPos against a known set before calling SetChartProperties."],"exampleFix":"// before\nSetChartProperties(part, new() { [\"labelPos\"] = \"outer\" });\n// after\nvar allowed = new[]{\"ctr\",\"inbase\",\"inend\",\"outend\",\"t\",\"b\",\"l\",\"r\",\"bestfit\"};\nvar pos = userInput.Trim().ToLowerInvariant();\nif (!allowed.Contains(pos)) throw new ArgumentOutOfRangeException(nameof(pos));\nSetChartProperties(part, new() { [\"labelPos\"] = pos });","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> LabelPos =\n    new[]{\"center\",\"ctr\",\"insidebase\",\"inbase\",\"base\",\"insideend\",\"inend\",\"inside\",\n          \"outsideend\",\"outend\",\"outside\",\"top\",\"t\",\"bottom\",\"b\",\"left\",\"l\",\n          \"right\",\"r\",\"bestfit\",\"best\",\"auto\"}, StringComparer.OrdinalIgnoreCase);\n\nstatic bool IsValidLabelPos(string v) =>\n    !string.IsNullOrWhiteSpace(v) && LabelPos.Contains(v.Trim().ToLowerInvariant());","typeGuard":"static bool IsKnownLabelPos(string v) =>\n    LabelPos.Contains((v ?? \"\").Trim().ToLowerInvariant());","tryCatchPattern":"try { SetChartProperties(part, props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid labelPos\"))\n{ /* log the offending value and the accepted alias list */ }","preventionTips":["Trim and ToLowerInvariant all free-text enum inputs before passing.","Expose label position as a dropdown bound to the accepted set, not a free textbox.","Whitelist enum tokens at the config boundary."],"tags":["ooxml","chart","input-validation","data-labels","csharp"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}