{"record":{"id":"c71e331a8b2ef8d5","repo":"iOfficeAI/OfficeCLI","slug":"axis-with-role-carole-not-found-on-chart-cach","errorCode":null,"errorMessage":"Axis with role '{caRole}' not found on chart {caChartIdx}.","messagePattern":"Axis with role '(.+?)' not found on chart (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Query.cs","lineNumber":682,"sourceCode":"        // Per schemas/help/pptx/chart-axis.json (shared contract).\n        var chartAxisGetMatch = Regex.Match(cellRef,\n            @\"^chart\\[(\\d+)\\]/axis\\[@role=([a-zA-Z0-9_]+)\\]$\");\n        if (chartAxisGetMatch.Success)\n        {\n            var caChartIdx = int.Parse(chartAxisGetMatch.Groups[1].Value);\n            var caRole = chartAxisGetMatch.Groups[2].Value;\n            var caDrawingsPart = worksheet.DrawingsPart;\n            if (caDrawingsPart == null)\n                throw new ArgumentException($\"No charts found in sheet\");\n            var caAllCharts = GetExcelCharts(caDrawingsPart);\n            if (caChartIdx < 1 || caChartIdx > caAllCharts.Count)\n                throw new ArgumentException($\"Chart index {caChartIdx} out of range (1-{caAllCharts.Count})\");\n            var caChartInfo = caAllCharts[caChartIdx - 1];\n            if (caChartInfo.IsExtended || caChartInfo.StandardPart?.ChartSpace == null)\n                throw new ArgumentException($\"Axis not available on chart {caChartIdx}: extended charts not supported.\");\n            var axisNode = ChartHelper.BuildAxisNode(caChartInfo.StandardPart.ChartSpace, caRole, path);\n            if (axisNode == null)\n                throw new ArgumentException($\"Axis with role '{caRole}' not found on chart {caChartIdx}.\");\n            return axisNode;\n        }\n\n        // Chart path: /Sheet1/chart[N] or /Sheet1/chart[N]/series[K]\n        var chartMatch = Regex.Match(cellRef, @\"^chart\\[(\\d+)\\](?:/series\\[(\\d+)\\])?$\");\n        if (chartMatch.Success)\n        {\n            var chartIdx = int.Parse(chartMatch.Groups[1].Value);\n            var drawingsPart = worksheet.DrawingsPart;\n            if (drawingsPart == null)\n                throw new ArgumentException($\"No charts found in sheet\");\n\n            var allCharts = GetExcelCharts(drawingsPart);\n            if (chartIdx < 1 || chartIdx > allCharts.Count)\n                throw new ArgumentException($\"Chart index {chartIdx} out of range (1-{allCharts.Count})\");\n\n            var chartInfo = allCharts[chartIdx - 1];\n            var chartNode = new DocumentNode { Path = $\"/{sheetNameFromPath}/chart[{chartIdx}]\", Type = \"chart\" };","sourceCodeStart":664,"sourceCodeEnd":700,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Query.cs#L664-L700","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar axis = handler.Get(\"/Sheet1/chart[1]/axis[@role=secondary]\"); // throws if none\n\n// after\ntry { var axis = handler.Get(\"/Sheet1/chart[1]/axis[@role=secondary]\"); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"not found\")) { /* no such role; try @role=primary */ }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static bool IsValidAxisRole(string role) =>\n    Regex.IsMatch(role, @\"^[a-zA-Z0-9_]+$\") && // shape only\n    new[] { \"primary\", \"secondary\", \"category\", \"value\", \"series\" }.Contains(role.ToLowerInvariant());","tryCatchPattern":"try { return handler.Get(\"/Sheet1/chart[1]/axis[@role=secondary]\"); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"not found\")) { /* role absent; try @role=primary */ return null; }","preventionTips":["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."],"tags":["excel","charts","axis","role","argument-exception"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}