{"record":{"id":"5a50cdfd76f9cd55","repo":"iOfficeAI/OfficeCLI","slug":"file-not-found","errorCode":"file_not_found","errorMessage":"File not found: {file.FullName}","messagePattern":"File not found: (.+?)","errorType":"error_code","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.Batch.cs","lineNumber":339,"sourceCode":"            // ExecuteBatchItem. Reject up-front with a recognizable error\n            // pointing at the offending index.\n            for (int ni = 0; ni < items.Count; ni++)\n            {\n                if (items[ni] == null)\n                    throw new ArgumentException(\n                        $\"batch item[{ni}] is null. Each entry must be a JSON object (e.g. {{\\\"command\\\":\\\"get\\\",\\\"path\\\":\\\"/\\\"}}).\");\n            }\n            if (items.Count == 0)\n            {\n                // BUG-R6-07: empty command array previously short-circuited\n                // before the file-existence check, so\n                //   officecli batch /missing.docx --commands '[]' --json\n                // returned a clean zero-result success instead of the\n                // expected file_not_found. Validate the target file\n                // exists first so empty-array semantics match the\n                // non-empty path's diagnostics.\n                if (!file.Exists)\n                    throw new CliException($\"File not found: {file.FullName}\")\n                        { Code = \"file_not_found\" };\n                // BUG-R7-09: in --json mode an empty/null batch input\n                // previously skipped the {\"success\":...,\"data\":{...}}\n                // envelope used by the populated-array path, so AI agents\n                // saw a missing `success` key. Apply the same envelope\n                // wrap here for shape parity.\n                if (json)\n                {\n                    using var sw = new System.IO.StringWriter();\n                    PrintBatchResults(new List<BatchResult>(), json, 0, sw);\n                    var inner = sw.ToString().TrimEnd('\\n', '\\r');\n                    Console.WriteLine(OfficeCli.Core.OutputFormatter.WrapEnvelope(inner));\n                }\n                else\n                {\n                    PrintBatchResults(new List<BatchResult>(), json, 0);\n                }\n                return 0;","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.Batch.cs#L321-L357","documentation":"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`.","triggerScenarios":"`officecli batch /missing.docx --commands '[]'`, or `--input empty.json` where empty.json is `[]` and the target doc is absent.","commonSituations":"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.","solutions":["Confirm the target document path exists: `ls -l <file>`; fix the path or create the doc first.","If the empty array is intentional, point it at a real document — the no-op is only valid against an existing file.","Check the generating step that produced an empty command list to ensure the document path is correct."],"exampleFix":"# before\nofficecli batch /misspelled.docx --commands '[]'\n\n# after\nofficecli batch ./actual.docx --commands '[]'","handlingStrategy":"validation","validationCode":"// For the empty-array path, verify the target document exists first.\nif (items.Count == 0 && !File.Exists(file.FullName))\n    throw new FileNotFoundException($\"target document not found: {file.FullName}\");","typeGuard":"// Guard: target doc exists before a (possibly empty) batch runs.\nstatic bool TargetReady(string file) => File.Exists(file);","tryCatchPattern":null,"preventionTips":["Validate the target document path once at the start of your pipeline, independent of ops count.","Treat an empty ops array as still requiring a valid target — do not special-case it as a no-op."],"tags":["file-not-found","batch","empty-array","known-bug"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}