iOfficeAI/OfficeCLI · error · ArgumentException
Axis with role '{caRole}' not found on chart {caChartIdx}.
Error message
Axis with role '{caRole}' not found on chart {caChartIdx}. What it means
Thrown for /Sheet/chart[N]/axis[@role=R] when chart N exists and is a standard chart, but no axis with the requested role name R is found. ChartHelper.BuildAxisNode returns null when the role doesn't match any axis on that chart (per the shared chart-axis.json contract).
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Query.cs:682
// Per schemas/help/pptx/chart-axis.json (shared contract).
var chartAxisGetMatch = Regex.Match(cellRef,
@"^chart\[(\d+)\]/axis\[@role=([a-zA-Z0-9_]+)\]$");
if (chartAxisGetMatch.Success)
{
var caChartIdx = int.Parse(chartAxisGetMatch.Groups[1].Value);
var caRole = chartAxisGetMatch.Groups[2].Value;
var caDrawingsPart = worksheet.DrawingsPart;
if (caDrawingsPart == null)
throw new ArgumentException($"No charts found in sheet");
var caAllCharts = GetExcelCharts(caDrawingsPart);
if (caChartIdx < 1 || caChartIdx > caAllCharts.Count)
throw new ArgumentException($"Chart index {caChartIdx} out of range (1-{caAllCharts.Count})");
var caChartInfo = caAllCharts[caChartIdx - 1];
if (caChartInfo.IsExtended || caChartInfo.StandardPart?.ChartSpace == null)
throw new ArgumentException($"Axis not available on chart {caChartIdx}: extended charts not supported.");
var axisNode = ChartHelper.BuildAxisNode(caChartInfo.StandardPart.ChartSpace, caRole, path);
if (axisNode == null)
throw new ArgumentException($"Axis with role '{caRole}' not found on chart {caChartIdx}.");
return axisNode;
}
// Chart path: /Sheet1/chart[N] or /Sheet1/chart[N]/series[K]
var chartMatch = Regex.Match(cellRef, @"^chart\[(\d+)\](?:/series\[(\d+)\])?$");
if (chartMatch.Success)
{
var chartIdx = int.Parse(chartMatch.Groups[1].Value);
var drawingsPart = worksheet.DrawingsPart;
if (drawingsPart == null)
throw new ArgumentException($"No charts found in sheet");
var allCharts = GetExcelCharts(drawingsPart);
if (chartIdx < 1 || chartIdx > allCharts.Count)
throw new ArgumentException($"Chart index {chartIdx} out of range (1-{allCharts.Count})");
var chartInfo = allCharts[chartIdx - 1];
var chartNode = new DocumentNode { Path = $"/{sheetNameFromPath}/chart[{chartIdx}]", Type = "chart" };View on GitHub (pinned to 1ced45e900)
Solutions
- Use a role that exists on that chart (commonly primary / category / value per the chart-axis schema).
- Enumerate the chart's axes/roles first if an axis-list path is available.
- Catch ArgumentException and surface the valid roles to the caller.
Example fix
// before
var axis = handler.Get("/Sheet1/chart[1]/axis[@role=secondary]"); // throws if none
// after
try { var axis = handler.Get("/Sheet1/chart[1]/axis[@role=secondary]"); }
catch (ArgumentException ex) when (ex.Message.Contains("not found")) { /* no such role; try @role=primary */ } Defensive patterns
Strategy: try-catch
Type guard
static bool IsValidAxisRole(string role) =>
Regex.IsMatch(role, @"^[a-zA-Z0-9_]+$") && // shape only
new[] { "primary", "secondary", "category", "value", "series" }.Contains(role.ToLowerInvariant()); Try / catch
try { return handler.Get("/Sheet1/chart[1]/axis[@role=secondary]"); }
catch (ArgumentException ex) when (ex.Message.Contains("not found")) { /* role absent; try @role=primary */ return null; } Prevention
- Not every chart has both primary and secondary axes.
- Use role names from the chart-axis schema (primary / category / value).
- Don't copy an axis path from one chart type to another.
When it happens
Trigger: handler.Get("/Sheet1/chart[1]/axis[@role=secondary]") when the chart has no secondary axis. Misspelled role (e.g. @role=primray). Using a role valid for a different chart type.
Common situations: Assuming every chart has both primary and secondary axes. Role-name mismatch between the schema and the document. Copying an axis path from one chart type to another.
Related errors
- No charts found in sheet
- Chart index {caChartIdx} out of range (1-{caAllCharts.Count}
- Axis not available on chart {caChartIdx}: extended charts no
- Chart index {chartIdx} out of range (1-{allCharts.Count})
- Series {seriesIdx} not found (total: {seriesChildren.Count})
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/c71e331a8b2ef8d5.
Report an issue: GitHub.