{"record":{"id":"f262ae74682dd447","repo":"iOfficeAI/OfficeCLI","slug":"invalid-key-value-expected-a-percentage-0","errorCode":null,"errorMessage":"Invalid {key}: '{value}'. Expected a percentage 0-100.","messagePattern":"Invalid (.+?): '(.+?)'\\. Expected a percentage 0-100\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/Chart/ChartHelper.Setter.cs","lineNumber":1338,"sourceCode":"                        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))\n                        alphaPercent = 100.0 - alphaPercent;\n                    var alphaVal = (int)(alphaPercent * 1000); // OOXML uses 1/1000th percent\n                    foreach (var ser in plotArea2.Descendants<OpenXmlCompositeElement>().Where(e => e.LocalName == \"ser\"))\n                        ApplySeriesAlpha(ser, alphaVal);\n                    break;\n                }\n\n                // ---- #6 Gradient fill ----\n                // CONSISTENCY(gradient-fill-alias): accept `gradientFill=` as an\n                // alias for `gradient=` so chart vocabulary matches shape/textbox\n                // (ExcelHandler.Add.cs line 1931 / Set.cs line 727 use\n                // BuildShapeGradientFill keyed on `gradientFill`).\n                case \"gradient\" or \"gradientfill\":\n                {\n                    var plotArea2 = chart.GetFirstChild<C.PlotArea>();\n                    if (plotArea2 == null) { unsupported.Add(key); break; }","sourceCodeStart":1320,"sourceCodeEnd":1356,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/Chart/ChartHelper.Setter.cs#L1320-L1356","documentation":"Thrown when 'transparency', 'opacity', or 'alpha' is outside 0-100, or is NaN/Infinity. The computed OOXML alpha val is percent*1000 and must land in [0,100000]; out-of-range input produces a schema-invalid file PowerPoint/Excel refuse. 'transparency' is converted to opacity (100-x) after the range check, so 30% transparency is valid.","triggerScenarios":"SetChartProperties with { [\"transparency\"] = \"120\" }, \"-5\", \"NaN\", or any value < 0 or > 100.","commonSituations":"Mixing up 0-1 fraction (0.3) with 0-100 percent (30); UI slider returning >100; infinity from a division-by-zero in alpha computation.","solutions":["Express transparency/opacity/alpha as an integer/float percentage in [0,100].","If your source uses 0-1, multiply by 100 before passing.","Reject NaN/Infinity upstream (e.g. from a ratio with zero denominator)."],"exampleFix":"// before\nSetChartProperties(part, new() { [\"transparency\"] = \"0.3\" }); // meant 30%\n// after\nSetChartProperties(part, new() { [\"transparency\"] = \"30\" });","handlingStrategy":"validation","validationCode":"static bool IsValidPercent(string v, out double pct) =>\n    double.TryParse(v, NumberStyles.Float, CultureInfo.InvariantCulture, out pct)\n    && !double.IsNaN(pct) && !double.IsInfinity(pct) && pct >= 0 && pct <= 100;","typeGuard":"static bool IsPercent(double v) =>\n    !double.IsNaN(v) && !double.IsInfinity(v) && v is >= 0 and <= 100;","tryCatchPattern":"try { SetChartProperties(part, props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Expected a percentage 0-100\"))\n{ /* rescale a 0-1 fraction to 0-100 and retry */ }","preventionTips":["Decide once whether your app uses 0-1 or 0-100 and convert at the boundary.","Reject NaN/Infinity from ratio computations before they reach the chart.","Bind alpha sliders to the 0-100 range."],"tags":["ooxml","chart","input-validation","alpha","csharp"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}