{"record":{"id":"ae3775a98fa1eed4","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-cmtsheetname","errorCode":null,"errorMessage":"Sheet not found: {cmtSheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs","lineNumber":250,"sourceCode":"        }\n\n        workbook.Save();\n\n        var nrIdx = PathIndex.FromArrayIndex(definedNames.Elements<DefinedName>().ToList().IndexOf(dn));\n        return $\"/namedrange[{nrIdx}]\";\n    }\n\n    private string AddComment(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)\n    {\n        var index = position?.Index;\n        var cmtSegments = parentPath.TrimStart('/').Split('/', 2);\n        var cmtSheetName = cmtSegments[0];\n        // Extract cell reference from path if present (e.g., /Sheet1/A1 -> A1)\n        string? cmtRefFromPath = null;\n        if (cmtSegments.Length > 1 && Regex.IsMatch(cmtSegments[1], @\"^[A-Z]+\\d+$\", RegexOptions.IgnoreCase))\n            cmtRefFromPath = cmtSegments[1];\n        var cmtWorksheet = FindWorksheet(cmtSheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {cmtSheetName}\");\n\n        var cmtRef = properties.GetValueOrDefault(\"ref\") ?? cmtRefFromPath\n            ?? throw new ArgumentException(\"Property 'ref' is required for comment\");\n        // Validate cell reference up-front; ParseCellReference rejects bad\n        // syntax, out-of-range rows (>1048576), and out-of-range columns (>XFD)\n        // with a clear ArgumentException — matches the validation surface\n        // already enforced for cells/ranges elsewhere.\n        ParseCellReference(cmtRef);\n        var cmtText = properties.GetValueOrDefault(\"text\", \"\");\n        var cmtAuthor = properties.GetValueOrDefault(\"author\", \"Author\");\n        OfficeCli.Core.ParseHelpers.ValidateXmlText(cmtText, \"comment text\");\n        OfficeCli.Core.ParseHelpers.ValidateXmlText(cmtAuthor, \"comment author\");\n\n        var commentsPart = cmtWorksheet.WorksheetCommentsPart\n            ?? cmtWorksheet.AddNewPart<WorksheetCommentsPart>();\n\n        if (commentsPart.Comments == null)\n        {","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs#L232-L268","documentation":"Thrown by AddComment when FindWorksheet(cmtSheetName) returns null. The sheet name is taken from the first segment of parentPath (after trimming a leading '/'). It is the plain inline form ('Sheet not found: <name>'), not the richer SheetNotFoundException that lists available sheets, so the message gives only the missing name.","triggerScenarios":"Call Add with type \"comment\"/\"note\" and a parentPath whose first segment is not a worksheet in the workbook, e.g. \"/TypoSheet/A1\".","commonSituations":"Sheet-name typo; the sheet was renamed or deleted between runs; leading/trailing whitespace or a path that omits the leading slash after normalization; copy-pasting a path from another workbook.","solutions":["List the real sheet names via handler.GetDumpSheetNames() and use an exact name.","Correct the parentPath first segment to match an existing sheet (matching is case-insensitive).","If the sheet genuinely should exist, add it first with type \"sheet\"."],"exampleFix":"// before\nhandler.Add(\"/Sheet1/A1\", \"comment\", null, new() { [\"text\"] = \"hi\" });\n// no sheet 'Sheet1' (it is 'Data')\n// after\nhandler.Add(\"/Data/A1\", \"comment\", null, new() { [\"text\"] = \"hi\" });","handlingStrategy":"validation","validationCode":"var sheet = parentPath.TrimStart('/').Split('/', 2)[0];\nif (!handler.GetDumpSheetNames()\n        .Any(n => n.Equals(sheet, StringComparison.OrdinalIgnoreCase)))\n    throw new InvalidOperationException($\"No sheet '{sheet}'. Available: \" +\n        string.Join(\", \", handler.GetDumpSheetNames()));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always resolve sheet names from GetDumpSheetNames() rather than hard-coding.","Normalize parentPath to start with '/' and split on '/' before calling.","Re-fetch the sheet list after any add/remove of sheets in the same run."],"tags":["excel","sheet","path","not-found","comment"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}