iOfficeAI/OfficeCLI · error · ArgumentException

'set' command requires 'path' field. Example: {"command": "s

Error message

'set' command requires 'path' field. Example: {"command": "set", "path": "/slide[1]", "props": {"bold": "true"}}

What it means

Thrown by ExecuteBatchItem for a batch "set" step when item.Path is null or empty. Set must target a specific node; there is no implicit root target. This mirrors the standalone set command's required path argument.

Source

Thrown at src/officecli/CommandBuilder.cs:982

                var selector = item.Selector ?? item.Path ?? "";
                if (string.IsNullOrEmpty(selector))
                    throw new ArgumentException("'query' command requires 'selector' field. Example: {\"command\": \"query\", \"selector\": \"row[Score>80]\"}");
                Func<string, string>? keyResolver =
                    handler is OfficeCli.Handlers.ExcelHandler
                    && OfficeCli.Handlers.ExcelHandler.SelectorTargetsCells(selector)
                        ? OfficeCli.Handlers.ExcelHandler.ResolveCellAttributeAlias : null;
                var (results, warnings) = OfficeCli.Core.AttributeFilter.FilterSelector(selector, handler.Query, keyResolver);
                if (item.Text is { } textFilter && !string.IsNullOrEmpty(textFilter))
                    // MatchesTextFilter (not plain Contains) so a batch query
                    // text filter honours r"regex" like the CLI and resident do.
                    results = results.Where(n => n.Text != null && OfficeCli.Core.AttributeFilter.MatchesTextFilter(n.Text, textFilter)).ToList();
                foreach (var w in warnings) Console.Error.WriteLine(w.Message);
                return OfficeCli.Core.OutputFormatter.FormatNodes(results, format);
            }
            case "set":
            {
                if (string.IsNullOrEmpty(item.Path))
                    throw new ArgumentException("'set' command requires 'path' field. Example: {\"command\": \"set\", \"path\": \"/slide[1]\", \"props\": {\"bold\": \"true\"}}");
                // Match standalone `set` rejection of empty/missing props — a
                // batch step with no props is a no-op that previously reported
                // success, hiding caller mistakes (forgotten props field,
                // misspelled key promoted to root, etc.).
                if (props.Count == 0)
                    throw new ArgumentException("'set' command requires 'props' field with at least one key=value. Got empty/missing props.");
                var path = item.Path;
                OfficeCli.Core.MutationSelectorGuard.EnsureScoped(path, "set");
                // Shared core: apply + prop-autocorrect + categorise. Identical
                // across CLI / batch / MCP / resident; only the output below is
                // batch-specific.
                var (applied, unsupported, autoCorrected) = ApplySetWithCorrection(handler, path, props);
                var parts = new List<string>();
                if (autoCorrected.Count > 0)
                    parts.Add("Auto-corrected: " + string.Join(", ", autoCorrected.Select(ac => $"{ac.Original}→{ac.Corrected}")));
                if (applied.Count > 0)
                {
                    var msg = $"Updated {path}: {string.Join(", ", applied.Select(kv => $"{kv.Key}={kv.Value}"))}";

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Add the target path: {"command":"set","path":"/slide[1]","props":{"bold":"true"}}.
  2. Ensure the path variable is non-null and non-empty before emitting the step.
  3. Validate every set step has a non-empty path before batch submission.
  4. If targeting the root, use an explicit root path accepted by the handler.

Example fix

// before
{"command":"set","props":{"bold":"true"}}
// after
{"command":"set","path":"/slide[1]","props":{"bold":"true"}}
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(item.Path))
    throw new ArgumentException("'set' requires a non-empty 'path'");

Type guard

static bool IsValidSetItem(BatchItem i)
    => !string.IsNullOrEmpty(i.Path) && (i.Props?.Count ?? 0) > 0;

Prevention

When it happens

Trigger: {"command":"set","props":{"bold":"true"}} (no path); a set step where the path variable was null/empty; a templating bug that dropped the path field.

Common situations: Forgotten path field in a hand-written batch; a path computed from a null/empty variable; a copy-paste that lost the path line; a generator that emitted props but not path.

Related errors


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