iOfficeAI/OfficeCLI · error · FileNotFoundException
OLE source file not found: {srcPath}
Error message
OLE source file not found: {srcPath} What it means
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).
Source
Thrown at src/officecli/Core/OleHelper.cs:158
"potm" => EmbeddedPackagePartType.Potm,
"ppam" => EmbeddedPackagePartType.Ppam,
"sldx" => EmbeddedPackagePartType.Sldx,
"sldm" => EmbeddedPackagePartType.Sldm,
"thmx" => EmbeddedPackagePartType.Thmx,
_ => null,
};
}
/// <summary>
/// Add an embedded part (package or generic object) to the given host
/// part, feed it the source file bytes, and return the rel id.
/// Works for any parent that supports embedded parts: MainDocumentPart,
/// WorksheetPart, SlidePart.
/// </summary>
public static (string RelId, OpenXmlPart Part) AddEmbeddedPart(OpenXmlPart host, string srcPath, string? hostDocumentPath = null)
{
if (!File.Exists(srcPath))
throw new FileNotFoundException($"OLE source file not found: {srcPath}");
// Warn (don't throw) when the source file is zero bytes and it is NOT
// a self-embed. Self-embed intentionally writes a zero-byte placeholder
// (see CONSISTENCY(ole-self-embed) block below) and should stay silent.
// Non-self-embed 0-byte files usually indicate a truncated or missing
// payload — the user deserves a visible warning so they know the
// embedded bytes are empty. We still proceed with the embed to match
// the existing "silently ignored → visibly ignored" contract.
var isSelfEmbed = hostDocumentPath != null && IsSameFile(srcPath, hostDocumentPath);
if (!isSelfEmbed && new FileInfo(srcPath).Length == 0)
{
var emptyMsg = $"OLE source file is empty (0 bytes): {srcPath}. Document will embed an empty payload.";
// CONSISTENCY(numfmt-warning): JSON mode → envelope warnings[];
// plain mode keeps the stderr line.
if (WarningContext.IsActive)
WarningContext.Add(emptyMsg, "empty_ole_source");
else
Console.Error.WriteLine($"Warning: {emptyMsg}");View on GitHub (pinned to 1ced45e900)
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.
Example fix
// before — file not found add ole src='report.pdf' path='/body' // after — use absolute path to existing file add ole src='/home/user/documents/report.pdf' path='/body'
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check OLE source file exists before embedding
if (!File.Exists(srcPath))
{
Console.Error.WriteLine($"OLE source file not found: {srcPath}");
return;
}
var (relId, part) = OleHelper.AddEmbeddedPart(hostPart, srcPath, hostDocumentPath); Try / catch
try
{
var (relId, part) = OleHelper.AddEmbeddedPart(hostPart, srcPath);
}
catch (FileNotFoundException ex) when (ex.Message.Contains("OLE source file not found"))
{
// Prompt for correct path or skip
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Image file not found: {path}
- Cannot read OLE source file '{srcPath}': the file is locked
- Input file not found: {inputFile.FullName}
- file_not_found
- file_not_found
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/6d3de18c9efafe6a.
Report an issue: GitHub.