{"record":{"id":"5132b94e9fe805d4","repo":"iOfficeAI/OfficeCLI","slug":"file-not-found-5132b9","errorCode":"file_not_found","errorMessage":"Template file not found: {templatePath}","messagePattern":"Template file not found: (.+?)","errorType":"error_code","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/TemplateMerger.cs","lineNumber":160,"sourceCode":"            else if (kvp.Value is JsonArray nestedArr)\n            {\n                FlattenArray(nestedArr, path, data);\n            }\n            else if (!data.ContainsKey(path))\n            {\n                data[path] = kvp.Value?.ToString() ?? \"\";\n            }\n        }\n    }\n\n    /// <summary>\n    /// Merge a template document with data. Copies template to output, then replaces placeholders.\n    /// Refuses to overwrite an existing output unless <paramref name=\"force\"/> is set.\n    /// </summary>\n    public static MergeResult Merge(string templatePath, string outputPath, Dictionary<string, string> data, bool force = false)\n    {\n        if (!File.Exists(templatePath))\n            throw new CliException($\"Template file not found: {templatePath}\")\n            {\n                Code = \"file_not_found\",\n                Suggestion = \"Check the template file path.\"\n            };\n\n        // Refuse to silently overwrite an existing output unless force is set,\n        // mirroring the `create` command's guard (CommandBuilder.Import.cs:185).\n        if (File.Exists(outputPath) && !force)\n            throw new CliException($\"Output file already exists: {outputPath}. Use --force to overwrite.\")\n            {\n                Code = \"file_exists\",\n                Suggestion = \"Add --force flag or remove the file first.\"\n            };\n\n        File.Copy(templatePath, outputPath, overwrite: true);\n\n        var ext = Path.GetExtension(outputPath).ToLowerInvariant();\n        return ext switch","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/TemplateMerger.cs#L142-L178","documentation":"Thrown by TemplateMerger.Merge when the template file does not exist on disk (File.Exists false). The merger copies the template to the output path before substituting placeholders, so a missing template cannot proceed. Reported as code file_not_found with a suggestion to check the path.","triggerScenarios":"Calling merge with a templatePath that does not exist; relative path resolved from an unexpected working directory; the template was moved/deleted.","commonSituations":"Wrong/relative path; CWD mismatch; template generated into a different location than expected.","solutions":["Verify the template path exists (File.Exists) and use an absolute path.","Check the working directory the command runs from.","Confirm the file was not deleted/moved before the merge."],"exampleFix":"// before\nvar result = TemplateMerger.Merge(\"tmpl/letter.docx\", out, data, false); // missing\n// after\nvar tpath = System.IO.Path.GetFullPath(\"tmpl/letter.docx\");\nif (!System.IO.File.Exists(tpath)) throw new FileNotFoundException(tpath);\nvar result = TemplateMerger.Merge(tpath, out, data, false);","handlingStrategy":"validation","validationCode":"if (!System.IO.File.Exists(templatePath))\n    throw new System.IO.FileNotFoundException(\"template not found\", templatePath);","typeGuard":null,"tryCatchPattern":"try { result = TemplateMerger.Merge(templatePath, outputPath, data, force); }\ncatch (CliException ex) when (ex.Code == \"file_not_found\")\n{ /* template path is wrong/missing; fix it */ }","preventionTips":["Resolve template paths to absolute before merging.","Validate inputs in the CLI/agent layer before calling Merge."],"tags":["filesystem","template","merge"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}