iOfficeAI/OfficeCLI · error · ArgumentException

Invalid overlap: '{value}'. Expected integer (-100 to 100).

Error message

Invalid overlap: '{value}'. Expected integer (-100 to 100).

What it means

Thrown when 'overlap' is not a parseable integer (int.TryParse fails). This is the parse-failure path; a second throw ('Valid range is -100 to 100.') handles integers outside that range. OOXML CT_Overlap is a signed byte (-100..100). Atomic — both checks run before any overlap element is mutated.

Source

Thrown at src/officecli/Core/Chart/ChartHelper.Setter.cs:1648

                        {
                            // Insert before the first AxisId — mirrors BuildBarChart's
                            // schema order: [barDirection, barGrouping, varyColors,
                            // ser*, gapWidth, overlap?, axisId+].
                            var axisIdEl = barChartEl.GetFirstChild<C.AxisId>();
                            if (axisIdEl != null)
                                axisIdEl.InsertBeforeSelf(new C.GapWidth { Val = (ushort)gw });
                            else
                                barChartEl.AppendChild(new C.GapWidth { Val = (ushort)gw });
                        }
                    }
                    break;
                }

                case "overlap":
                {
                    var plotArea2 = chart.GetFirstChild<C.PlotArea>();
                    if (plotArea2 == null) { unsupported.Add(key); break; }
                    if (!int.TryParse(value, out var ov)) throw new ArgumentException($"Invalid overlap: '{value}'. Expected integer (-100 to 100).");
                    if (ov < -100 || ov > 100) throw new ArgumentException($"Invalid overlap: '{value}'. Valid range is -100 to 100.");
                    var overlapBarEls = plotArea2.Elements<OpenXmlCompositeElement>()
                        .Where(e => e.LocalName.Contains("barChart") || e.LocalName.Contains("BarChart"))
                        .ToList();
                    if (overlapBarEls.Count == 0) { unsupported.Add(key); break; }
                    foreach (var barChart in overlapBarEls)
                    {
                        var overlapEl = barChart.GetFirstChild<C.Overlap>();
                        if (overlapEl != null) overlapEl.Val = (sbyte)ov;
                        else
                        {
                            var gapEl = barChart.GetFirstChild<C.GapWidth>();
                            if (gapEl != null) gapEl.InsertAfterSelf(new C.Overlap { Val = (sbyte)ov });
                            else barChart.AppendChild(new C.Overlap { Val = (sbyte)ov });
                        }
                    }
                    break;
                }

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Pass overlap as a plain integer string in -100..100.
  2. Strip '%' and parse to int upstream.
  3. Validate parse and range before calling Set.

Example fix

// before
SetChartProperties(part, new() { ["overlap"] = "50%" });
// after
SetChartProperties(part, new() { ["overlap"] = Math.Clamp(ov, -100, 100).ToString() });
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidOverlap(string v, out int ov) =>
    int.TryParse(v?.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out ov)
    && ov >= -100 && ov <= 100;

Type guard

static bool IsLegalOverlap(int ov) => ov is >= -100 and <= 100;

Try / catch

try { SetChartProperties(part, props); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid overlap"))
{ /* strip '%', parse, clamp to -100..100, retry */ }

Prevention

When it happens

Trigger: SetChartProperties with { ["overlap"] = "50%" }, "half", "0.5", or any non-integer token on a bar/column chart.

Common situations: Percentage suffix reuse; decimal overlap from a ratio; localized decimal separator.

Related errors


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