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
- Pass overlap as a plain integer string in -100..100.
- Strip '%' and parse to int upstream.
- 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
- Send overlap as a plain integer in -100..100, not a percentage.
- Validate both parse and range before calling Set.
- Use invariant-culture parsing.
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
- Invalid gapWidth: '{value}'. Expected integer (0-500).
- Invalid gapWidth: '{value}'. Expected integer 0-500.
- Unknown chart preset '{value}'. Available: {string.Join(", "
- Invalid labelPos '{value}' for pie chart: ST_DLblPosPie allo
- Invalid labelPos '{value}': expected one of ctr, inBase, inE
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/5a2770d039781465.
Report an issue: GitHub.