{"record":{"id":"43445c0c840855ac","repo":"iOfficeAI/OfficeCLI","slug":"sparkline-spkindex-not-found-in-sheet-sheetna","errorCode":null,"errorMessage":"Sparkline[{spkIndex}] not found in sheet '{sheetNameFromPath}'","messagePattern":"Sparkline\\[(.+?)\\] not found in sheet '(.+?)'","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Query.cs","lineNumber":863,"sourceCode":"            var ccf = tCol.CalculatedColumnFormula?.Text;\n            if (!string.IsNullOrEmpty(ccf)) tcNode.Format[\"formula\"] = ccf;\n            return tcNode;\n        }\n\n        // Cell reference: A1 or range A1:D10\n        // Check if it's a cell reference or a generic XML path\n        var firstPart = cellRef.Split('/')[0].Split('[')[0];\n        bool isCellRef = System.Text.RegularExpressions.Regex.IsMatch(firstPart, @\"^[A-Z]+\\d+\", System.Text.RegularExpressions.RegexOptions.IgnoreCase);\n\n        if (!isCellRef)\n        {\n            // Handle sparkline[N] path segment\n            var spkMatch = Regex.Match(cellRef, @\"^sparkline\\[(\\d+)\\]$\", RegexOptions.IgnoreCase);\n            if (spkMatch.Success)\n            {\n                var spkIndex = int.Parse(spkMatch.Groups[1].Value);\n                var spkGroup = GetSparklineGroup(worksheet, spkIndex)\n                    ?? throw new ArgumentException($\"Sparkline[{spkIndex}] not found in sheet '{sheetNameFromPath}'\");\n                return SparklineGroupToNode(sheetNameFromPath, spkGroup, spkIndex);\n            }\n\n            // Handle picture[N] path segment\n            var picMatch = Regex.Match(cellRef, @\"^picture\\[(\\d+)\\]$\", RegexOptions.IgnoreCase);\n            if (picMatch.Success)\n            {\n                var picIndex = int.Parse(picMatch.Groups[1].Value);\n                // GetPictureNode returns null for out-of-range indices (incl.\n                // picture[0]); the bare `!` leaked a NullReferenceException as\n                // an opaque internal_error instead of the not-found message\n                // every sibling element type produces.\n                return GetPictureNode(sheetNameFromPath, worksheet, picIndex, path)\n                    ?? throw new ArgumentException(\n                        $\"Picture[{picIndex}] not found in sheet '{sheetNameFromPath}' (indices are 1-based).\");\n            }\n\n            // Handle shape[N] path segment","sourceCodeStart":845,"sourceCodeEnd":881,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Query.cs#L845-L881","documentation":"Thrown for /Sheet/sparkline[N] when GetSparklineGroup returns no group at that 1-based index. Sparkline groups live in the worksheet's extLst under x14:sparklineGroups; with no groups on the sheet, any index (including sparkline[0]) is rejected.","triggerScenarios":"handler.Get(\"/Sheet1/sparkline[1]\") on a sheet with no sparkline groups. sparkline[0]. An index beyond the group count.","commonSituations":"Assuming sparklines exist on a sheet that has none. Hard-coded index after sparklines were removed. Zero-based indexing.","solutions":["Use a 1-based index within the sparkline-group count.","Confirm the sheet has sparkline groups before indexing.","try/catch(ArgumentException) and degrade to 'no sparkline'."],"exampleFix":"// before\nvar spk = handler.Get(\"/Sheet1/sparkline[1]\"); // throws if no groups\n\n// after\ntry { var spk = handler.Get(\"/Sheet1/sparkline[1]\"); }\ncatch (ArgumentException) { /* no sparkline group at that index */ }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static int? ElementIndex(string cellRef, string element)\n{\n    var m = Regex.Match(cellRef, $@\"^{Regex.Escape(element)}\\[(\\d+)$\", RegexOptions.IgnoreCase);\n    return m.Success && int.TryParse(m.Groups[1].Value, out var i) ? i : null;\n}","tryCatchPattern":"try { return handler.Get(\"/Sheet1/sparkline[1]\"); }\ncatch (ArgumentException) { /* no sparkline group at that index */ return null; }","preventionTips":["Sparkline indices are 1-based — there is no index 0.","Don't assume a sheet has sparkline groups.","Treat a not-found sparkline as empty, not fatal."],"tags":["excel","sparkline","path-index","argument-exception"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}