iOfficeAI/OfficeCLI · error · CliException
invalid_value
invalid_value
Error message
--compact is a plain-text line format; drop --json (or drop --compact for the JSON tree).
What it means
Thrown by the `query` command when both --compact and --json are supplied. --compact emits a plain-text, one-line-per-match tabular format incompatible with the JSON tree shape; the guard at line 192-193 rejects the combination with code `invalid_value` rather than producing ambiguous output.
Source
Thrown at src/officecli/CommandBuilder.GetQuery.cs:193
var queryFieldsOpt = new Option<string?>("--fields") { Description = "Comma-separated Format keys appended as extra k=v columns in --compact output (e.g. x,y,width)" };
var queryCommand = new Command("query", "Query document elements with CSS-like selectors");
queryCommand.Add(queryFileArg);
queryCommand.Add(selectorArg);
queryCommand.Add(jsonOption);
queryCommand.Add(queryFindOpt);
queryCommand.Add(queryCompactOpt);
queryCommand.Add(queryFieldsOpt);
queryCommand.SetAction(result => { var json = result.GetValue(jsonOption); return SafeRun(() =>
{
var file = result.GetValue(queryFileArg)!;
var selector = MsysPathHint.Restore(result.GetValue(selectorArg)!)!;
var textFilter = result.GetValue(queryFindOpt);
var compact = result.GetValue(queryCompactOpt);
var fields = result.GetValue(queryFieldsOpt);
if (compact && json)
throw new OfficeCli.Core.CliException("--compact is a plain-text line format; drop --json (or drop --compact for the JSON tree).") { Code = "invalid_value" };
if (TryResident(file.FullName, req =>
{
req.Command = "query";
req.Json = json;
req.Args["selector"] = selector;
if (textFilter != null) req.Args["find"] = textFilter;
if (compact) req.Args["compact"] = "true";
if (fields != null) req.Args["fields"] = fields;
}, json) is {} rc) return rc;
var format = json ? OutputFormat.Json : OutputFormat.Text;
using var handler = DocumentHandlerFactory.Open(file.FullName);
// CONSISTENCY(cell-selector-alias): the Excel cell selector accepts short
// aliases (bold -> font.bold, size -> font.size, ...). FilterSelector
// applies the same normalization, runs the boolean and/or engine, and
// routes a pure-AND (flat) selector through the exact legacy path.View on GitHub (pinned to 1ced45e900)
Solutions
- For machine-readable output, drop --compact and keep --json (returns the JSON tree).
- For compact tabular output, drop --json and keep --compact (plain text lines).
- Pick one output mode per invocation.
Example fix
# before officecli query file.docx 'p' --compact --json # after officecli query file.docx 'p' --json
Defensive patterns
Strategy: validation
Validate before calling
// Enforce mutual exclusivity of --compact and --json before invoking query.
if (compact && json) throw new ArgumentException("use --compact OR --json, not both"); Type guard
// Guard: exactly one output mode for query. static bool SingleQueryMode(bool compact, bool json) => !(compact && json);
Prevention
- Derive the output mode from a single enum in your wrapper, never two independent booleans.
- Default pipelines to --json; reserve --compact for human-facing terminal output.
When it happens
Trigger: `officecli query file.docx 'p' --compact --json`. compact && json is true triggers the throw.
Common situations: A script shares a flags object between query and get and inherits both; a user wants machine-readable output and adds --json on top of --compact; an agent stacks output-format flags assuming they compose.
Related errors
- invalid_argument
- batch: --commands and --input are mutually exclusive. Pick o
- invalid_format
- ${r.stderr || r.stdout}
- missing_argument
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/4b5b9b6a888f8098.
Report an issue: GitHub.