{"record":{"id":"571110bf4a1f931a","repo":"iOfficeAI/OfficeCLI","slug":"invalid-style-value-valid-range-is-1-48","errorCode":null,"errorMessage":"Invalid style: '{value}'. Valid range is 1-48.","messagePattern":"Invalid style: '(.+?)'\\. Valid range is 1-48\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/Chart/ChartHelper.Setter.cs","lineNumber":1322,"sourceCode":"                        if (ser is not (C.LineChartSeries or C.ScatterChartSeries or C.RadarChartSeries))\n                            continue;\n                        // Reuse the per-series dotted-property handler so\n                        // symbol/size are preserved and schema-order insertion\n                        // stays in one place.\n                        HandleSeriesDottedProperty(ser, \"markercolor\", value);\n                    }\n                    break;\n                }\n\n                // ---- #4 Chart style ID ----\n                case \"style\" or \"styleid\":\n                {\n                    chartSpace!.RemoveAllChildren<C.Style>();\n                    if (!value.Equals(\"none\", StringComparison.OrdinalIgnoreCase))\n                    {\n                        var styleVal = ParseHelpers.SafeParseInt(value, \"style\");\n                        if (styleVal < 1 || styleVal > 48)\n                            throw new ArgumentException($\"Invalid style: '{value}'. Valid range is 1-48.\");\n                        chartSpace.InsertBefore(new C.Style { Val = (byte)styleVal }, chart);\n                    }\n                    break;\n                }\n\n                // ---- #5 Fill transparency ----\n                case \"transparency\" or \"opacity\" or \"alpha\":\n                {\n                    var plotArea2 = chart.GetFirstChild<C.PlotArea>();\n                    if (plotArea2 == null) { unsupported.Add(key); break; }\n                    var alphaPercent = ParseHelpers.SafeParseDouble(value, key);\n                    // BUGFIX (NumericBoundaryScanTests): transparency/opacity/alpha\n                    // are 0-100 percent. Out-of-range input drove the computed\n                    // <a:alpha val> outside [0,100000] → schema-invalid file.\n                    if (double.IsNaN(alphaPercent) || double.IsInfinity(alphaPercent) || alphaPercent < 0 || alphaPercent > 100)\n                        throw new ArgumentException($\"Invalid {key}: '{value}'. Expected a percentage 0-100.\");\n                    // If key is \"transparency\", convert to opacity (e.g. 30% transparency = 70% opacity)\n                    if (key.Equals(\"transparency\", StringComparison.OrdinalIgnoreCase))","sourceCodeStart":1304,"sourceCodeEnd":1340,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/Chart/ChartHelper.Setter.cs#L1304-L1340","documentation":"Thrown when 'style'/'styleId' parses to an integer outside 1-48 (the OOXML chart style gallery range, CT_Style/ST_StyleUByte). NOTE an atomicity caveat: chartSpace.RemoveAllChildren<C.Style>() runs BEFORE the range check, so an out-of-range value deletes the existing style and then throws, leaving the chart without a style element. SafeParseInt rejects non-integer input earlier.","triggerScenarios":"SetChartProperties with { [\"style\"] = \"0\" }, \"50\", \"99\", or \"100\". The value 'none' is special-cased to delete the style without throwing.","commonSituations":"UI style picker with no bounds; config referencing a 1-indexed style by a 0-indexed value; copy from a theme that exposes >48 styles.","solutions":["Clamp style to the 1-48 range before passing (or pass 'none' to remove it).","Validate the integer bounds in your own config loader.","If relying on the current style, do not send an out-of-range value — it will be wiped on the throw."],"exampleFix":"// before\nSetChartProperties(part, new() { [\"style\"] = \"0\" });\n// after\nvar style = Math.Clamp(userStyle, 1, 48);\nSetChartProperties(part, new() { [\"style\"] = style.ToString() });","handlingStrategy":"validation","validationCode":"static bool IsValidChartStyle(string v, out int style) =>\n    (v.Equals(\"none\", StringComparison.OrdinalIgnoreCase))\n    || (int.TryParse(v, out style) && style >= 1 && style <= 48);","typeGuard":"static bool IsLegalStyleId(string v) =>\n    v.Equals(\"none\", StringComparison.OrdinalIgnoreCase)\n    || (int.TryParse(v, out var s) && s is >= 1 and <= 48);","tryCatchPattern":"try { SetChartProperties(part, props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Valid range is 1-48\"))\n{ /* NOTE: the prior style was already deleted — re-apply a valid style */ }","preventionTips":["Clamp style to 1-48 before sending; do not rely on the throw (it fires AFTER the existing style is wiped).","Bind style pickers to the 1-48 gallery range.","Avoid 0-indexed style IDs from external themes."],"tags":["ooxml","chart","input-validation","style","csharp","atomicity"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}