{"record":{"id":"5c8fc68b9280eee9","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-rbsheetname","errorCode":null,"errorMessage":"Sheet not found: {rbSheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"validation","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Cells.cs","lineNumber":1327,"sourceCode":"        return $\"/{runSheetName}/{runCellRef}/run[{runIndex}]\";\n    }\n\n    private string AddPageBreak(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)\n    {\n        var index = position?.Index;\n        // Route to rowbreak or colbreak based on properties\n        if (properties.ContainsKey(\"col\") || properties.ContainsKey(\"column\"))\n            return Add(parentPath, \"colbreak\", position, properties);\n        return Add(parentPath, \"rowbreak\", position, properties);\n    }\n\n    private string AddRowBreak(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)\n    {\n        var index = position?.Index;\n        var rbSegments = parentPath.TrimStart('/').Split('/', 2);\n        var rbSheetName = rbSegments[0];\n        var rbWorksheet = FindWorksheet(rbSheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {rbSheetName}\");\n        var rbWs = GetSheet(rbWorksheet);\n\n        var rbRowIdx = uint.Parse(properties.GetValueOrDefault(\"row\") ?? properties.GetValueOrDefault(\"index\")\n            ?? throw new ArgumentException(\"'row' property is required for rowbreak\"));\n        // A break id of 0 or beyond the grid fails the schema's Min/Max\n        // constraints — reject up front instead of writing invalid OOXML.\n        if (rbRowIdx < 1 || rbRowIdx > 1048576)\n            throw new ArgumentException(\n                $\"Invalid 'row' value: '{rbRowIdx}'. Row breaks must be between 1 and 1048576.\");\n\n        var rowBreaks = rbWs.GetFirstChild<RowBreaks>();\n        if (rowBreaks == null)\n        {\n            rowBreaks = new RowBreaks();\n            rbWs.AppendChild(rowBreaks);\n        }\n        // Optional restricted column span (min/max) — mirrors the Set path so a\n        // dump-emitted `add rowbreak row=N min=.. max=..` reproduces a","sourceCodeStart":1309,"sourceCodeEnd":1345,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Cells.cs#L1309-L1345","documentation":"Thrown by AddRowBreak when FindWorksheet(rbSheetName) returns null. The sheet name is taken from the first segment of parentPath (after trimming the leading slash). Unlike AddRun there is no prior path-length check, so any parentPath whose first segment is not a real worksheet triggers this, including empty or malformed paths.","triggerScenarios":"Add type=rowbreak with parentPath=\"/BadSheet\" or parentPath=\"/BadSheet/...\". Also reachable when properties force routing here via AddRowBreak: if col/column keys are absent, Add dispatches to rowbreak. A typo or a deleted sheet name reproduces it.","commonSituations":"Dump-emitted rowbreak path uses a sheet name that was later renamed. Script targets a sheet from a different workbook. Trailing slash producing an empty first segment.","solutions":["Confirm the sheet exists via a Get on / and use the exact name.","Create the sheet first if it is missing.","Ensure parentPath starts with /<existingSheetName>."],"exampleFix":"// before\nhandler.Add(\"/SheetX\", \"rowbreak\", null, new() { [\"row\"] = \"5\" }); // SheetX missing\n\n// after\nhandler.Add(\"/Sheet1\", \"rowbreak\", null, new() { [\"row\"] = \"5\" });","handlingStrategy":"validation","validationCode":"string sheet = \"Sheet1\";\nvar sheets = handler.Query(\"/\");\nif (!sheets.Any(s => string.Equals(s.Name, sheet, StringComparison.OrdinalIgnoreCase)))\n    throw new InvalidOperationException($\"Sheet not found: {sheet}\");\nhandler.Add(\"/\" + sheet, \"rowbreak\", null, props);","typeGuard":"static bool SheetExists(IExcelHandler h, string sheet)\n    => h.Query(\"/\").Any(s => string.Equals(s.Name, sheet, StringComparison.OrdinalIgnoreCase));","tryCatchPattern":"try { handler.Add(parentPath, \"rowbreak\", null, props); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Sheet not found\"))\n{ /* create the sheet or surface the missing name */ }","preventionTips":["Resolve sheet names from a freshly queried sheet list.","Create the sheet before adding breaks to it.","Build paths with a /{sheet} helper to avoid dropping the leading segment."],"tags":["excel","ooxml","rowbreak","sheet-not-found","argument"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}