{"record":{"id":"bbdef0d9f7681573","repo":"iOfficeAI/OfficeCLI","slug":"raw-command-requires-part-field-example-co","errorCode":null,"errorMessage":"'raw' command requires 'part' field. Example: {\"command\": \"raw\", \"part\": \"/document\"} (docx), {\"command\": \"raw\", \"part\": \"/presentation\"} (pptx), {\"command\": \"raw\", \"part\": \"/sheet[1]\"} (xlsx)","messagePattern":"'raw' command requires 'part' field\\. Example: (.+?) \\(docx\\), (.+?) \\(pptx\\), (.+?) \\(xlsx\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.cs","lineNumber":1209,"sourceCode":"                }\n                if (mode.ToLowerInvariant() is \"svg\" or \"g\" && handler is OfficeCli.Handlers.PowerPointHandler pptSvg)\n                {\n                    return pptSvg.ViewAsSvg(1);\n                }\n                return mode.ToLowerInvariant() switch\n                {\n                    \"text\" or \"t\" => handler.ViewAsText(null, null, null, null),\n                    \"annotated\" or \"a\" => handler.ViewAsAnnotated(null, null, null, null),\n                    \"outline\" or \"o\" => handler.ViewAsOutline(),\n                    \"stats\" or \"s\" => handler.ViewAsStats(),\n                    \"issues\" or \"i\" => OfficeCli.Core.OutputFormatter.FormatIssues(handler.ViewAsIssues(null, null), format),\n                    _ => $\"Unknown mode: {mode}\"\n                };\n            }\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}\";","sourceCodeStart":1191,"sourceCodeEnd":1227,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.cs#L1191-L1227","documentation":"Thrown by the batch 'raw' command when item.Part is null or empty. The raw command reads a raw XML part from the package by its part path (e.g. /document, /presentation, /sheet[1]), so a missing target is a hard error. The message lists the per-document-type root part examples.","triggerScenarios":"A batch item {\"command\":\"raw\"} with no 'part' field, or a caller that puts the part under 'path' instead of 'part'.","commonSituations":"An agent confuses 'raw' with 'get' (which uses path) and omits 'part'. A caller assumes a default part exists — there is none; the field is mandatory.","solutions":["Add a 'part' field with the package part path: /document (docx), /presentation (pptx), /sheet[1] (xlsx).","Use 'view' or 'get' if you actually wanted a logical element rather than the raw XML part.","Run 'raw' once with a known part to discover the package structure, then target sub-parts."],"exampleFix":"// before\n{\"command\":\"raw\"}\n// after\n{\"command\":\"raw\",\"part\":\"/document\"}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(item.Part))\n    throw new ArgumentException(\"'raw' requires 'part', e.g. /document (docx), /presentation (pptx), /sheet[1] (xlsx)\");","typeGuard":"static bool HasRawPart(BatchItem i) => !string.IsNullOrEmpty(i.Part);","tryCatchPattern":"try { result = Dispatch(item); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"'raw' command requires 'part'\"))\n{ /* ask caller for the part path */ }","preventionTips":["Remember 'raw' uses 'part', not 'path' — keep field names per-verb straight.","Cache the per-document root part (/document, /presentation, /sheet[1]) in a lookup.","Use 'view' or 'get' if you want a logical element rather than raw XML."],"tags":["batch","raw","missing-field","part","xml"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}