{"record":{"id":"c4711f5ab3201d62","repo":"iOfficeAI/OfficeCLI","slug":"add-part-command-requires-parent-field-exampl","errorCode":null,"errorMessage":"'add-part' command requires 'parent' field. Example: {\"command\": \"add-part\", \"parent\": \"/slide[1]\", \"type\": \"smartart\", \"props\": {\"data\": \"rId2\"}}","messagePattern":"'add-part' command requires 'parent' field\\. Example: (.+?)\\}","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.cs","lineNumber":1223,"sourceCode":"            }\n            case \"raw\":\n            {\n                if (string.IsNullOrEmpty(item.Part))\n                    throw new ArgumentException(\"'raw' command requires 'part' field. Example: {\\\"command\\\": \\\"raw\\\", \\\"part\\\": \\\"/document\\\"} (docx), {\\\"command\\\": \\\"raw\\\", \\\"part\\\": \\\"/presentation\\\"} (pptx), {\\\"command\\\": \\\"raw\\\", \\\"part\\\": \\\"/sheet[1]\\\"} (xlsx)\");\n                return handler.Raw(item.Part, null, null, null);\n            }\n            case \"raw-set\":\n            {\n                var partPath = item.Part ?? \"/document\";\n                var xpath = item.Xpath ?? \"\";\n                var action = item.Action ?? \"\";\n                handler.RawSet(partPath, xpath, action, item.Xml);\n                return $\"raw-set {action} applied\";\n            }\n            case \"add-part\":\n            {\n                if (string.IsNullOrEmpty(item.Parent))\n                    throw new ArgumentException(\"'add-part' command requires 'parent' field. Example: {\\\"command\\\": \\\"add-part\\\", \\\"parent\\\": \\\"/slide[1]\\\", \\\"type\\\": \\\"smartart\\\", \\\"props\\\": {\\\"data\\\": \\\"rId2\\\"}}\");\n                if (string.IsNullOrEmpty(item.Type))\n                    throw new ArgumentException(\"'add-part' command requires 'type' field. Supported (pptx): chart, smartart, video, audio, model3d, ole, image, hyperlink, theme.\");\n                var (relId, partOut) = handler.AddPart(item.Parent, item.Type, props);\n                return $\"Created {item.Type} part: relId={relId} path={partOut}\";\n            }\n            case \"validate\":\n            {\n                var errors = handler.Validate();\n                if (errors.Count == 0) return \"Validation passed: no errors found.\";\n                var lines = new List<string> { $\"Found {errors.Count} validation error(s):\" };\n                foreach (var err in errors)\n                {\n                    lines.Add($\"  [{err.ErrorType}] {err.Description}\");\n                    if (err.Path != null) lines.Add($\"    Path: {err.Path}\");\n                    if (err.Part != null) lines.Add($\"    Part: {err.Part}\");\n                }\n                return string.Join(\"\\n\", lines);\n            }","sourceCodeStart":1205,"sourceCodeEnd":1241,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.cs#L1205-L1241","documentation":"Thrown by the batch 'add-part' command when item.Parent is null or empty. add-part attaches a new package part (chart, smartart, image, …) to a parent element/container, so the attachment point is mandatory. The parent must be an existing, addressable element path.","triggerScenarios":"A batch item {\"command\":\"add-part\",\"type\":\"image\"} with no 'parent'. A caller that names the parent 'path' or 'container' instead of 'parent'.","commonSituations":"An agent builds an add-part item and remembers 'type' and 'props' but forgets 'parent'. A caller copies a 'shape' add template (which uses parent/type) but drops parent.","solutions":["Add a 'parent' field pointing at the container that owns the new part, e.g. /slide[1].","Ensure the parent path exists before add-part (the relationship cannot target a non-existent element).","Then also set 'type' and, usually, a 'props' object (the next guard requires type)."],"exampleFix":"// before\n{\"command\":\"add-part\",\"type\":\"smartart\"}\n// after\n{\"command\":\"add-part\",\"parent\":\"/slide[1]\",\"type\":\"smartart\",\"props\":{\"data\":\"rId2\"}}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(item.Parent))\n    throw new ArgumentException(\"'add-part' requires 'parent', e.g. /slide[1]\");","typeGuard":"static bool HasAddPartParent(BatchItem i) => !string.IsNullOrEmpty(i.Parent);","tryCatchPattern":"try { (relId, part) = Dispatch(item); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"'add-part' command requires 'parent'\"))\n{ /* resolve a parent path and retry */ }","preventionTips":["Validate 'parent' exists before add-part (target a real element).","Keep 'parent' and 'type' together in add-part templates.","Do not substitute 'path' or 'container' for 'parent'."],"tags":["batch","add-part","missing-field","parent"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}