iOfficeAI/OfficeCLI · error · ArgumentException

'add-part' command requires 'type' field. Supported (pptx):

Error message

'add-part' command requires 'type' field. Supported (pptx): chart, smartart, video, audio, model3d, ole, image, hyperlink, theme.

What it means

Thrown by the batch 'add-part' command when item.Type is null or empty (after parent has already been validated). The type selects which kind of package part to create; without it the handler cannot dispatch. The message enumerates the pptx-supported types so the caller can pick the right one.

Source

Thrown at src/officecli/CommandBuilder.cs:1225

            {
                if (string.IsNullOrEmpty(item.Part))
                    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)");
                return handler.Raw(item.Part, null, null, null);
            }
            case "raw-set":
            {
                var partPath = item.Part ?? "/document";
                var xpath = item.Xpath ?? "";
                var action = item.Action ?? "";
                handler.RawSet(partPath, xpath, action, item.Xml);
                return $"raw-set {action} applied";
            }
            case "add-part":
            {
                if (string.IsNullOrEmpty(item.Parent))
                    throw new ArgumentException("'add-part' command requires 'parent' field. Example: {\"command\": \"add-part\", \"parent\": \"/slide[1]\", \"type\": \"smartart\", \"props\": {\"data\": \"rId2\"}}");
                if (string.IsNullOrEmpty(item.Type))
                    throw new ArgumentException("'add-part' command requires 'type' field. Supported (pptx): chart, smartart, video, audio, model3d, ole, image, hyperlink, theme.");
                var (relId, partOut) = handler.AddPart(item.Parent, item.Type, props);
                return $"Created {item.Type} part: relId={relId} path={partOut}";
            }
            case "validate":
            {
                var errors = handler.Validate();
                if (errors.Count == 0) return "Validation passed: no errors found.";
                var lines = new List<string> { $"Found {errors.Count} validation error(s):" };
                foreach (var err in errors)
                {
                    lines.Add($"  [{err.ErrorType}] {err.Description}");
                    if (err.Path != null) lines.Add($"    Path: {err.Path}");
                    if (err.Part != null) lines.Add($"    Part: {err.Part}");
                }
                return string.Join("\n", lines);
            }
            default:
                if (string.IsNullOrEmpty(item.Command))

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Add a 'type' field with one of: chart, smartart, video, audio, model3d, ole, image, hyperlink, theme (pptx).
  2. Make sure 'type' is a top-level item field, not nested inside 'props'.
  3. Check the per-document-type supported list in the message — not all types exist for every format.

Example fix

// before
{"command":"add-part","parent":"/slide[1]","props":{"data":"rId2"}}
// after
{"command":"add-part","parent":"/slide[1]","type":"smartart","props":{"data":"rId2"}}
Defensive patterns

Strategy: validation

Validate before calling

var pptxPartTypes = new[] { "chart","smartart","video","audio","model3d","ole","image","hyperlink","theme" };
if (string.IsNullOrEmpty(item.Type))
    throw new ArgumentException("'add-part' requires 'type' from: " + string.Join(", ", pptxPartTypes));

Type guard

static bool HasAddPartType(BatchItem i) => !string.IsNullOrEmpty(i.Type);

Try / catch

try { (relId, part) = Dispatch(item); }
catch (ArgumentException ex) when (ex.Message.Contains("'add-part' command requires 'type'"))
{ /* pick a supported type and retry */ }

Prevention

When it happens

Trigger: An add-part item with 'parent' set but 'type' omitted or empty. A caller that puts the kind under 'props.kind' instead of the top-level 'type' field.

Common situations: An agent emits the parent (copied from a remove/add template) and a props blob but forgets the verb-specific 'type'. A caller uses a synonym like 'kind' or 'category'.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/5c5617d561c06d34. Report an issue: GitHub.