iOfficeAI / iOfficeAI/OfficeCLI
[Bug] set: a command that fails (unknown sheet) still rewrites and re-saves the file, with the audit stamp
- Dominant language
- C#
- Stars
- 30.8k
- Forks
- 2.1k
- Avg merge
- 9d 8h
- Merged PRs (30d)
- 5
Description
## Summary
A `set` that fails (here: unknown sheet) exits 1 with a clear error, but the file on disk is still rewritten and re-saved: parts are re-serialised, `docProps/custom.xml` gains the `OfficeCLI.Version` / `OfficeCLI.LastModified` audit stamp, and the SHA-256 changes. Happens both with `OFFICECLI_NO_AUTO_RESIDENT=1` and in the default resident mode (visible after `close`).
## Environment
officecli 1.0.149 (Homebrew, dotnet 10.0.400), macOS 26.4.1 arm64.
## Reproduction
Any `.xlsx` works; this uses the file from #389 (a sheet with a chart):
```bash
cp min_order.xlsx f1.xlsx
shasum -a 256 f1.xlsx
OFFICECLI_NO_AUTO_RESIDENT=1 officecli set f1.xlsx /NoSuchSheet/A1 --prop value=1
# Error: Sheet not found: "NoSuchSheet". Available sheets: [Sheet1]. ...
echo $? # 1
shasum -a 256 f1.xlsx # different
```
Parts that differ between input and output: `xl/worksheets/sheet1.xml`, `xl/charts/chart1.xml`, `_rels/.rels`, `xl/workbook.xml`, `[Content_Types].xml`; `docProps/custom.xml` is added with the two `OfficeCLI.*` properties.
Same in resident mode:
```bash
cp min_order.xlsx f2.xlsx
officecli set f2.xlsx /NoSuchSheet/A1 --prop value=1 # exit 1
officecli close f2.xlsx
shasum -a 256 f2.xlsx # different
```
A plain `get` on the same file leaves it byte-identical, as expected.
## Why it matters
Combined with the element-order bug in #389, a command that did nothing turns a good workbook into one Excel wants to repair. More generally, an audit stamp saying OfficeCLI modified the file is written for a command that was refused.
## Expected
A command that fails before mutating anything leaves the file untouched: no re-serialisation, no audit stamp, same hash.
Contributor guide
Research direction
Start by reproducing the failure with `officecli set f1.xlsx /NoSuchSheet/A1 --prop value=1`, then compare the input and output hashes and workbook parts listed in the issue. Check the `set` and resident-mode `close` entry points to find why a rejected command still saves; done means the error still exits 1 while the file remains byte-identical with no audit stamp.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100