{"record":{"id":"a927a9985db35c81","repo":"iOfficeAI/OfficeCLI","slug":"query-command-requires-selector-field-example","errorCode":null,"errorMessage":"'query' command requires 'selector' field. Example: {\"command\": \"query\", \"selector\": \"row[Score>80]\"}","messagePattern":"'query' command requires 'selector' field\\. Example: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.cs","lineNumber":966,"sourceCode":"                    throw new ArgumentException(node.Text ?? $\"Path not found: {path}\");\n                // Unified envelope: batch get items emit the same\n                // {matches, results: [...]} shape as query items, so callers\n                // can consume batch step output with a single parser.\n                if (format == OutputFormat.Json)\n                    return OfficeCli.Core.OutputFormatter.FormatNodes(new List<DocumentNode> { node }, format);\n                return OfficeCli.Core.OutputFormatter.FormatNode(node, format);\n            }\n            case \"query\":\n            {\n                // `path` is accepted as an alias for `selector` — the generic\n                // field table says \"path (set/remove/get target)\" and users\n                // carry it over to query; ignoring it silently ran an EMPTY\n                // selector, i.e. returned every node as if the predicate\n                // matched (the most dangerous kind of wrong data). Neither\n                // field present is an error, mirroring the required CLI arg.\n                var selector = item.Selector ?? item.Path ?? \"\";\n                if (string.IsNullOrEmpty(selector))\n                    throw new ArgumentException(\"'query' command requires 'selector' field. Example: {\\\"command\\\": \\\"query\\\", \\\"selector\\\": \\\"row[Score>80]\\\"}\");\n                Func<string, string>? keyResolver =\n                    handler is OfficeCli.Handlers.ExcelHandler\n                    && OfficeCli.Handlers.ExcelHandler.SelectorTargetsCells(selector)\n                        ? OfficeCli.Handlers.ExcelHandler.ResolveCellAttributeAlias : null;\n                var (results, warnings) = OfficeCli.Core.AttributeFilter.FilterSelector(selector, handler.Query, keyResolver);\n                if (item.Text is { } textFilter && !string.IsNullOrEmpty(textFilter))\n                    // MatchesTextFilter (not plain Contains) so a batch query\n                    // text filter honours r\"regex\" like the CLI and resident do.\n                    results = results.Where(n => n.Text != null && OfficeCli.Core.AttributeFilter.MatchesTextFilter(n.Text, textFilter)).ToList();\n                foreach (var w in warnings) Console.Error.WriteLine(w.Message);\n                return OfficeCli.Core.OutputFormatter.FormatNodes(results, format);\n            }\n            case \"set\":\n            {\n                if (string.IsNullOrEmpty(item.Path))\n                    throw new ArgumentException(\"'set' command requires 'path' field. Example: {\\\"command\\\": \\\"set\\\", \\\"path\\\": \\\"/slide[1]\\\", \\\"props\\\": {\\\"bold\\\": \\\"true\\\"}}\");\n                // Match standalone `set` rejection of empty/missing props — a\n                // batch step with no props is a no-op that previously reported","sourceCodeStart":948,"sourceCodeEnd":984,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.cs#L948-L984","documentation":"Thrown by ExecuteBatchItem for a batch \"query\" step when both \"selector\" and \"path\" are null/empty. An empty selector would silently match every node (the most dangerous wrong-data outcome), so it is rejected. \"path\" is accepted as an alias for \"selector\" to mirror the CLI, so setting either satisfies the requirement.","triggerScenarios":"{\"command\":\"query\"} with no fields; {\"command\":\"query\",\"selector\":\"\"}; a query step whose selector field was misspelled (e.g. \"selectr\").","commonSituations":"A template that omits the selector; a field misspelling; an AI/LLM-generated batch that dropped the field; a dynamic selector variable that evaluated to empty.","solutions":["Add a selector: {\"command\":\"query\",\"selector\":\"row[Score>80]\"}.","If you intended to target a path, set \"path\" instead (it is accepted as an alias).","Validate every query step has a non-empty selector/path before submitting the batch.","Check for misspelled field names against the documented schema."],"exampleFix":"// before\n{\"command\":\"query\"}\n// after\n{\"command\":\"query\",\"selector\":\"row[Score>80]\"}","handlingStrategy":"validation","validationCode":"var selector = item.Selector ?? item.Path;\nif (string.IsNullOrEmpty(selector))\n    throw new ArgumentException(\"'query' requires a non-empty 'selector' (or 'path')\");","typeGuard":"static bool IsValidQueryItem(BatchItem i)\n    => !string.IsNullOrEmpty(i.Selector) || !string.IsNullOrEmpty(i.Path);","tryCatchPattern":null,"preventionTips":["Always set selector (or path) on query steps.","Validate the batch schema before submission.","Watch for misspelled field names."],"tags":["batch","query","validation","officecli"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}