{"record":{"id":"2ff9145c2aad0c96","repo":"iOfficeAI/OfficeCLI","slug":"invalid-gapwidth-value-expected-integer-0-5","errorCode":null,"errorMessage":"Invalid gapWidth: '{value}'. Expected integer (0-500).","messagePattern":"Invalid gapWidth: '(.+?)'\\. Expected integer \\(0-500\\)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/Chart/ChartHelper.Setter.cs","lineNumber":1604,"sourceCode":"                            var sf = new Drawing.SolidFill();\n                            sf.AppendChild(BuildChartColorElement(outParts[0]));\n                            outline.AppendChild(sf);\n                            if (outParts.Length > 2 && !string.IsNullOrEmpty(outParts[2]))\n                                outline.AppendChild(new Drawing.PresetDash { Val = ParseDashStyle(outParts[2]) });\n                            // Insert ln before effectLst per DrawingML schema order\n                            var effLst = spPr.GetFirstChild<Drawing.EffectList>();\n                            if (effLst != null) spPr.InsertBefore(outline, effLst);\n                            else spPr.AppendChild(outline);\n                        }\n                    }\n                    break;\n                }\n\n                case \"gapwidth\" or \"gap\":\n                {\n                    var plotArea2 = chart.GetFirstChild<C.PlotArea>();\n                    if (plotArea2 == null) { unsupported.Add(key); break; }\n                    if (!int.TryParse(value, out var gw)) throw new ArgumentException($\"Invalid gapWidth: '{value}'. Expected integer (0-500).\");\n                    // BUGFIX (NumericBoundaryScanTests): enforce the stated 0-500\n                    // range. CT_GapAmount is ST_GapAmountUShort (0-500); out-of-range\n                    // (incl. negatives wrapping via (ushort) cast) produced a\n                    // schema-invalid c:gapWidth PowerPoint refuses to open.\n                    if (gw < 0 || gw > 500) throw new ArgumentException($\"Invalid gapWidth: '{value}'. Expected integer 0-500.\");\n                    bool gapUpdated = false;\n                    foreach (var gapEl in plotArea2.Descendants<C.GapWidth>())\n                    {\n                        gapEl.Val = (ushort)gw;\n                        gapUpdated = true;\n                    }\n                    if (!gapUpdated)\n                    {\n                        // No existing GapWidth — create one per bar/column chart element.\n                        // This occurs when RebuildComboChart (applied via deferred\n                        // comboTypes= prop) replaces the original barChart (which had\n                        // a GapWidth seeded by BuildBarChart) with freshly constructed\n                        // barChart elements that have no GapWidth child. The `foreach","sourceCodeStart":1586,"sourceCodeEnd":1622,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/Chart/ChartHelper.Setter.cs#L1586-L1622","documentation":"Thrown when 'gapWidth'/'gap' is not a parseable integer (int.TryParse fails). This is the parse-failure path; a separate range check (error 153) handles integers outside 0-500. OOXML CT_GapAmount is ST_GapAmountUShort (0-500); a non-integer string cannot be cast and is rejected up front before any gap element is mutated.","triggerScenarios":"SetChartProperties with { [\"gapWidth\"] = \"50%\" }, \"narrow\", \"1.5\", or any non-integer token.","commonSituations":"Percentage suffix from a CSS-like config (\"20%\"); decimal gap from a ratio; localized number with a comma decimal separator.","solutions":["Pass gapWidth as a plain integer string (e.g. \"150\").","Strip '%' and parse to int in your config loader.","Use CultureInfo-invariant parsing if you pre-validate."],"exampleFix":"// before\nSetChartProperties(part, new() { [\"gapWidth\"] = \"50%\" });\n// after\nSetChartProperties(part, new() { [\"gapWidth\"] = \"50\" });","handlingStrategy":"validation","validationCode":"static bool IsIntegerGapWidth(string v, out int gw) =>\n    int.TryParse(v?.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out gw);","typeGuard":"static bool IsPlainInteger(string v) =>\n    int.TryParse((v ?? \"\").Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out _);","tryCatchPattern":"try { SetChartProperties(part, props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"gapWidth\") && ex.Message.Contains(\"integer\"))\n{ /* strip '%', parse to int, retry */ }","preventionTips":["Strip '%' and parse to int in your config loader before sending.","Do not send decimals or localized numbers as gapWidth.","Use invariant-culture parsing for all numeric chart keys."],"tags":["ooxml","chart","input-validation","bar-chart","csharp"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}