iOfficeAI/OfficeCLI · error · CliException

file_not_found

file_not_found

Error message

File not found: {file.FullName}

What it means

Thrown by the `batch` command when the command array is empty AND the target document file does not exist. Tagged BUG-R6-07: previously an empty array short-circuited to a clean zero-result success before the file-existence check, so `batch /missing.docx --commands '[]'` returned success instead of file_not_found. Now the empty-array path validates the file first (line 338-340) with code `file_not_found`.

Source

Thrown at src/officecli/CommandBuilder.Batch.cs:339

            // ExecuteBatchItem. Reject up-front with a recognizable error
            // pointing at the offending index.
            for (int ni = 0; ni < items.Count; ni++)
            {
                if (items[ni] == null)
                    throw new ArgumentException(
                        $"batch item[{ni}] is null. Each entry must be a JSON object (e.g. {{\"command\":\"get\",\"path\":\"/\"}}).");
            }
            if (items.Count == 0)
            {
                // BUG-R6-07: empty command array previously short-circuited
                // before the file-existence check, so
                //   officecli batch /missing.docx --commands '[]' --json
                // returned a clean zero-result success instead of the
                // expected file_not_found. Validate the target file
                // exists first so empty-array semantics match the
                // non-empty path's diagnostics.
                if (!file.Exists)
                    throw new CliException($"File not found: {file.FullName}")
                        { Code = "file_not_found" };
                // BUG-R7-09: in --json mode an empty/null batch input
                // previously skipped the {"success":...,"data":{...}}
                // envelope used by the populated-array path, so AI agents
                // saw a missing `success` key. Apply the same envelope
                // wrap here for shape parity.
                if (json)
                {
                    using var sw = new System.IO.StringWriter();
                    PrintBatchResults(new List<BatchResult>(), json, 0, sw);
                    var inner = sw.ToString().TrimEnd('\n', '\r');
                    Console.WriteLine(OfficeCli.Core.OutputFormatter.WrapEnvelope(inner));
                }
                else
                {
                    PrintBatchResults(new List<BatchResult>(), json, 0);
                }
                return 0;

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Confirm the target document path exists: `ls -l <file>`; fix the path or create the doc first.
  2. If the empty array is intentional, point it at a real document — the no-op is only valid against an existing file.
  3. Check the generating step that produced an empty command list to ensure the document path is correct.

Example fix

# before
officecli batch /misspelled.docx --commands '[]'

# after
officecli batch ./actual.docx --commands '[]'
Defensive patterns

Strategy: validation

Validate before calling

// For the empty-array path, verify the target document exists first.
if (items.Count == 0 && !File.Exists(file.FullName))
    throw new FileNotFoundException($"target document not found: {file.FullName}");

Type guard

// Guard: target doc exists before a (possibly empty) batch runs.
static bool TargetReady(string file) => File.Exists(file);

Prevention

When it happens

Trigger: `officecli batch /missing.docx --commands '[]'`, or `--input empty.json` where empty.json is `[]` and the target doc is absent.

Common situations: A pipeline generates an empty ops array (no work to do) but points at a wrong/missing document; a template run before the document exists; a typo in the document path combined with a no-op batch.

Related errors


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