{"record":{"id":"6d3de18c9efafe6a","repo":"iOfficeAI/OfficeCLI","slug":"ole-source-file-not-found-srcpath","errorCode":null,"errorMessage":"OLE source file not found: {srcPath}","messagePattern":"OLE source file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/OleHelper.cs","lineNumber":158,"sourceCode":"            \"potm\" => EmbeddedPackagePartType.Potm,\n            \"ppam\" => EmbeddedPackagePartType.Ppam,\n            \"sldx\" => EmbeddedPackagePartType.Sldx,\n            \"sldm\" => EmbeddedPackagePartType.Sldm,\n            \"thmx\" => EmbeddedPackagePartType.Thmx,\n            _ => null,\n        };\n    }\n\n    /// <summary>\n    /// Add an embedded part (package or generic object) to the given host\n    /// part, feed it the source file bytes, and return the rel id.\n    /// Works for any parent that supports embedded parts: MainDocumentPart,\n    /// WorksheetPart, SlidePart.\n    /// </summary>\n    public static (string RelId, OpenXmlPart Part) AddEmbeddedPart(OpenXmlPart host, string srcPath, string? hostDocumentPath = null)\n    {\n        if (!File.Exists(srcPath))\n            throw new FileNotFoundException($\"OLE source file not found: {srcPath}\");\n\n        // Warn (don't throw) when the source file is zero bytes and it is NOT\n        // a self-embed. Self-embed intentionally writes a zero-byte placeholder\n        // (see CONSISTENCY(ole-self-embed) block below) and should stay silent.\n        // Non-self-embed 0-byte files usually indicate a truncated or missing\n        // payload — the user deserves a visible warning so they know the\n        // embedded bytes are empty. We still proceed with the embed to match\n        // the existing \"silently ignored → visibly ignored\" contract.\n        var isSelfEmbed = hostDocumentPath != null && IsSameFile(srcPath, hostDocumentPath);\n        if (!isSelfEmbed && new FileInfo(srcPath).Length == 0)\n        {\n            var emptyMsg = $\"OLE source file is empty (0 bytes): {srcPath}. Document will embed an empty payload.\";\n            // CONSISTENCY(numfmt-warning): JSON mode → envelope warnings[];\n            // plain mode keeps the stderr line.\n            if (WarningContext.IsActive)\n                WarningContext.Add(emptyMsg, \"empty_ole_source\");\n            else\n                Console.Error.WriteLine($\"Warning: {emptyMsg}\");","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/OleHelper.cs#L140-L176","documentation":"Thrown by OleHelper.AddEmbeddedPart when File.Exists(srcPath) returns false for an OLE source file. This is the entry point for embedding files (PDF, Office docs, binaries) as OLE objects in Word/Excel/PowerPoint. The FileNotFoundException includes the path verbatim. Note: a 0-byte file that DOES exist does not throw here — it generates a warning instead and proceeds with an empty payload (unless it's a self-embed).","triggerScenarios":"Calling any handler's Add ole operation with a 'src' path that doesn't exist on disk. For example: 'add ole src=/tmp/missing.pdf' where the file is absent. The check fires before any OLE packaging or CFB wrapping occurs.","commonSituations":"A relative path that doesn't resolve from the process working directory. A file that was moved or deleted after the command was constructed. A path with a typo. A containerized environment where the path isn't mounted. Case-sensitivity mismatches on Linux/macOS.","solutions":["Verify the file exists at the given path using an absolute path.","Check the process working directory and use absolute paths for OLE source files.","Ensure the file hasn't been moved, deleted, or renamed since the command was prepared.","On case-sensitive filesystems, match the exact casing of the filename."],"exampleFix":"// before — file not found\nadd ole src='report.pdf' path='/body'\n\n// after — use absolute path to existing file\nadd ole src='/home/user/documents/report.pdf' path='/body'","handlingStrategy":"validation","validationCode":"// Pre-check OLE source file exists before embedding\nif (!File.Exists(srcPath))\n{\n    Console.Error.WriteLine($\"OLE source file not found: {srcPath}\");\n    return;\n}\nvar (relId, part) = OleHelper.AddEmbeddedPart(hostPart, srcPath, hostDocumentPath);","typeGuard":null,"tryCatchPattern":"try\n{\n    var (relId, part) = OleHelper.AddEmbeddedPart(hostPart, srcPath);\n}\ncatch (FileNotFoundException ex) when (ex.Message.Contains(\"OLE source file not found\"))\n{\n    // Prompt for correct path or skip\n}","preventionTips":["Always use absolute paths for OLE source files.","Call File.Exists before invoking Add ole to provide your own error context.","Verify the file path in containerized or cross-platform environments where mount points differ."],"tags":["ole","file-not-found","path-validation","add-command","embedding"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}