set/add: an unknown option placed after `--prop` is swallowed into the property values — so the guard written to catch it (which names `--at A2`) never fires, and the same token is refused one position earlier
Summary
set and add declare --prop as a multi-value option (Option<string[]> with AllowMultipleArgumentsPerToken = true), which makes it a greedy token sink: every following token that is not a recognized option is consumed as a property value.
Two consequences fall out of that one declaration:
An unknown option placed after
--propnever reaches the guard written to catch it.RejectUnknownOptionTokens(CommandBuilder.cs:1611) exists precisely for this, and its own doc-comment names the motivating case:"Commands parsed with TreatUnmatchedTokensAsErrors=false otherwise swallow unknown flags (e.g.
add ... --at A2) silently with exit 0 — the element lands somewhere the caller did not intend and nothing surfaces the typo."But because the sink has already eaten the token, it never appears in
UnmatchedTokens, so the guard cannot see it. The same token is refused or silently swallowed depending only on its position relative to--prop:command line rc result add f.xlsx /Sheet1 --type sheet --zzz A2 --prop name=S91 Unrecognized option '--zzz'.add f.xlsx /Sheet1 --type sheet --prop name=S9 --zzz A20 Added sheet at /S9— nothing reportedA
--propvalue without=is dropped with no branch to report it.ParsePropsArray(CommandBuilder.cs:1285) treatseqIdx == 0as a hard error — added deliberately bya6ed9fe5("fix(cli): reject --prop with empty key instead of silent drop"), whose comment gives the reason as "So AI callers don't waste a turn wondering why their property had no effect." The other malformed form,eqIdx == -1, has no branch at all — the value is simply never stored:command line rc warnings set f.xlsx /Sheet1/A1 --prop value=NEW BARE0 none set f.xlsx /Sheet1/A1 --prop value=NEW bogusprop=12 unsupported_property(the positive control — see below)setcalls the guard nowhere. The only call site ofRejectUnknownOptionTokensisAdd.cs:123;Set.csdoes not reference it. So even when a token does land inUnmatchedTokens(--propnot yet seen),setdoes not name it:set f.xlsx /Sheet1/A1 --zzz A2 --prop value=NEW→ rc 0, where the identical shape onadd→ rc 1.
Environment
- OfficeCLI 1.0.151 (released binary), macOS 26.6.2 arm64
- Source read at both revisions: the working tree (local HEAD
1f0fd193) andorigin/main(dced0d74).git diff HEAD origin/mainover the three files involved (CommandBuilder.cs,CommandBuilder.Set.cs,CommandBuilder.Add.cs) contains only an unrelatedmove --indexhelp-text change, so every anchor below also holds in the revision the released binary was built from. - No .NET SDK on this machine: every behavioural row is measured on the released binary; every source claim is read-from-source and labelled as such.
The position experiment (measured)
Method: each shape on a freshly created file seeded with sentinels (A1=BASE, B1=BEEE), so a swallowed argument shows up as "the sentinel still stands". Outcomes are read from the JSON envelope and from the sheet XML bytes, not from the prose.
| shape | rc | observed |
|---|---|---|
add … --zzz A2 (no --prop anywhere) |
1 | Unrecognized option '--zzz'. — guard fires |
add … --zzz A2 --prop name=S9 (junk before --prop) |
1 | Unrecognized option '--zzz'. — guard fires |
add … --prop name=S9 --zzz A2 (junk after --prop) |
0 | Added sheet at /S9 — guard blind, token became a property value |
add … --prop name=S9 JUNK |
0 | Added sheet at /S9 — same |
set … --prop value=NEW --zzz A2 |
0 | Updated /Sheet1/A1: value=NEW |
set … --zzz A2 --prop value=NEW (junk before --prop) |
0 | Updated /Sheet1/A1 — set never calls the guard (contrast row 2) |
set … --prop value=NEW BARE |
0 | no warnings key at all |
set … --prop value=NEW bogusprop=1 |
2 | warnings: [{code: unsupported_property, …bogusprop…}] — positive control |
get … /Sheet1/A1 /Sheet1/B1 |
1 | Unrecognized command or argument '/Sheet1/B1'. — control |
remove … /Sheet1/B1 /Sheet1/A1 |
1 | Unrecognized command or argument '/Sheet1/A1'. — control |
The bogusprop=1 row is the load-bearing control: it proves the token really is being read as a property value (the sink exists), and it is the only one of these shapes that the existing warning machinery covers.
The strict verbs are otherwise strict — get, remove, validate, query, dump, raw, view all refuse a stray positional with Unrecognized command or argument '<tok>'. (rc 1). The tolerance introduced by TreatUnmatchedTokensAsErrors = false is confined to set and add, which is exactly why two checkers were written for it — but neither covers the shapes above.
Where it comes from (read from source)
The sink — src/officecli/CommandBuilder.Set.cs:17 and src/officecli/CommandBuilder.Add.cs:42:
var propsOpt = new Option<string[]>("--prop") { Description = "Property to set (key=value)", AllowMultipleArgumentsPerToken = true };The tolerance the guards exist for — Set.cs:23, Add.cs:45:
var setCommand = new Command("set", "Modify a document node's properties") { TreatUnmatchedTokensAsErrors = false };The guard, its blind spot, and its call sites — src/officecli/CommandBuilder.cs:1611-1637:
for (int i = 0; i < tokens.Count; i++)
{
var token = tokens[i];
if (!token.StartsWith("--") || token.Length <= 2) continue; // line 1622: only ever inspects --tokens
…
throw new OfficeCli.Core.CliException($"Unrecognized option '{token}'.") { Code = "invalid_argument", … };
}It iterates parseResult.UnmatchedTokens — a collection the sink has already removed the token from. Note also line 1622: a bare stray token (a second path, a stray word) is skipped by design, so this guard could not have caught the dropped-target case either. The only call site is Add.cs:123.
The drop — src/officecli/CommandBuilder.cs:1290-1321:
var eqIdx = prop.IndexOf('=');
// BUG-R40-B12: previously `eqIdx > 0` silently dropped both …
if (eqIdx == 0) throw new ArgumentException(…); // line 1296 — hardened
if (eqIdx > 0) { … dict[key] = value; } // line 1299 — the only storing branch
// eqIdx == -1: no branch — the value is never stored and nothing reports itThe commit that added line 1296 is a6ed9fe5, and the reasoning in its comment applies verbatim to the case it left unhandled.
Why this is more than an ugly error message
- The realistic harm is a dropped target, not a noisy typo.
set f.xlsx /Sheet1/A1 /Sheet1/B1 --prop value=NEWreturns rc 0, writes A1, and leaves B1 untouched (measured).getandremoverefuse a second path with the generic message;setaccepts and discards it. Same for a range followed by a cell, or a second sheet. - The outcome is position-dependent, which no design would state. The guard fires for
--zzz A2one token earlier and is blind one token later. That is an artifact of the sink, not a rule. setis the most-used mutation verb and has no guard call at all — onset, a stray option is only ever masked, never named. (When there are no props, an unrelated check happens to fire:set … --nope value=CH6→ rc 2missing_prop_flag;set … --definitely-not-an-option→ rc 1missing_property. Neither names the offending option, and neither fires when a valid--propis also present.)- This project has already ruled that this class is a defect.
3a5e4772added the guard specifically to stop unknown options being swallowed with exit 0, anda6ed9fe5hardened the empty-key form of exactly this parse loop for exactly this reason.
What I am not disputing: the caller wrote a malformed command line. The ask is that malformed input be refused — as it already is one position earlier, and as it already is in the eight strict verbs — rather than converted into a property value that is then dropped.
Suggested fix shape
- Call
RejectUnknownOptionTokensfromsettoo — it already hasresultin hand atSet.cs:139, right next to theDetectUnmatchedKeyValuescall. - Defeat the sink: after parsing, any element of the
propsarray that starts with--is a stray option, not a property value, and can be refused with the existingUnrecognized optionmessage. (Measured: that is exactly where--zzzcurrently lands.) - Give
eqIdx == -1inParsePropsArraythe same treatmentBUG-R40-B12gaveeqIdx == 0— the author's own stated reason applies unchanged. - Optional, same family: a bare non-
key=valuetoken inset/add(e.g. a second path) refused the wayget/removealready refuse it.
Constraints to preserve (all measured as currently correct):
--prop a=1 --prop b=2and--prop a=1 b=2— the multi-argument form is deliberate and used throughout the docs- the
missing_prop_flagwarning for a barek=v(rc 2) - the
missing_propertyerror for asetwith no props at all (rc 1) - the
--props/-props/--prop=typo hint (Pattern 3 inDetectUnmatchedKeyValues) - the strict verbs' generic refusal
I have not prepared a patch — no .NET SDK on this machine, so the fix is text-verified only, not compiled or test-run.
Reproduction
officecli create a.xlsx
# the guard fires when the junk precedes --prop
officecli add a.xlsx /Sheet1 --type sheet --zzz A2 --prop name=S9 --json ; echo "rc=$?"
# rc=1 "Unrecognized option '--zzz'."
# the same token one position later is swallowed
officecli add a.xlsx /Sheet1 --type sheet --prop name=S9 --zzz A2 --json ; echo "rc=$?"
# rc=0 "Added sheet at /S9"
# set does not call the guard at all
officecli set a.xlsx /Sheet1/A1 --zzz A2 --prop value=NEW --json ; echo "rc=$?"
# rc=0 "Updated /Sheet1/A1"
# a --prop value without '=' vanishes silently
officecli set a.xlsx /Sheet1/A1 --prop value=NEW BARE --json # rc=0, no "warnings"
# positive control: a swallowed value WITH '=' really is read as a property
officecli set a.xlsx /Sheet1/A1 --prop value=NEW bogusprop=1 --json ; echo "rc=$?"
# rc=2 warnings: [{code: "unsupported_property", … bogusprop …}]
# the realistic harm: a second target is accepted and dropped
officecli set a.xlsx /Sheet1/A1 --prop value=BASE
officecli set a.xlsx /Sheet1/B1 --prop value=BEEE
officecli set a.xlsx /Sheet1/A1 /Sheet1/B1 --prop value=NEW --json # rc=0, A1=NEW, B1 still BEEENot the same as other open reports
- #405 (closed) — unknown property keys silently discarded on
add/ generic error onset. Here the token is a stray option, and the second half is a property value with no=. Different code path (UnmatchedTokensplumbing andParsePropsArray), though the same family. - #399 §5 (ours, open) — the unknown-prop-key behaviour, inside a docs/consistency umbrella. This report is the neighbouring mechanism; I have not duplicated it there.
- #413 (ours) —
importtruncating its<parent-path>to the first segment. A different argument, a different verb, a different mechanism. (Relatedly:get/setdo run the cell validator onA1/B2— which is what makes #413'simportan outlier.) queryselectors that match nothing (matches: 0) andimportrefusing extra positionals are both correct behaviour — recorded so they are not mistaken for this.
Scope / honesty
- Behaviour measured on macOS arm64, OfficeCLI 1.0.151 only — Windows and Linux not measured.
- Source claims are read from
origin/main@dced0d74and the working tree @1f0fd193(the two differ only by an unrelated help string inAdd.cs); nothing here is compiled, and the fix shape is a proposal, not a verified patch. moveandswapalso carry a--propoption (Add.cs:425) and were not swept for the same sink — flagged as unmeasured rather than claimed.- The MCP and batch surfaces pass props as JSON objects, where this sink cannot exist by construction; no claim is made about them.
- Each shape above ran on a freshly created file, so no resident warm state carried between them.
Source: iOfficeAI/OfficeCLI