{"record":{"id":"89f0daab9ce37a7b","repo":"iOfficeAI/OfficeCLI","slug":"image-file-not-found-path","errorCode":null,"errorMessage":"Image file not found: {path}","messagePattern":"Image file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/ImageSource.cs","lineNumber":69,"sourceCode":"        var ext = extension.TrimStart('.').ToLowerInvariant();\n        return ext switch\n        {\n            \"png\" => ImagePartType.Png,\n            \"jpg\" or \"jpeg\" => ImagePartType.Jpeg,\n            \"gif\" => ImagePartType.Gif,\n            \"bmp\" => ImagePartType.Bmp,\n            \"tif\" or \"tiff\" => ImagePartType.Tiff,\n            \"emf\" => ImagePartType.Emf,\n            \"wmf\" => ImagePartType.Wmf,\n            \"svg\" => ImagePartType.Svg,\n            _ => throw new ArgumentException($\"Unsupported image format: .{ext}. Supported: png, jpg, gif, bmp, tiff, emf, wmf, svg\")\n        };\n    }\n\n    private static (Stream, PartTypeInfo) ResolveFile(string path)\n    {\n        if (!File.Exists(path))\n            throw new FileNotFoundException($\"Image file not found: {path}\");\n\n        var contentType = ExtensionToContentType(Path.GetExtension(path));\n        var ext = Path.GetExtension(path).TrimStart('.').ToLowerInvariant();\n\n        // Magic-byte validation for raster formats. SVG (XML) / EMF / WMF are\n        // intentionally skipped: SVG has no fixed magic, EMF/WMF have weaker\n        // headers and TrySniffContentType doesn't cover them. Only validate\n        // formats whose first 4 bytes are stable (png/jpg/gif/bmp/tiff).\n        var rasterExts = new[] { \"png\", \"jpg\", \"jpeg\", \"gif\", \"bmp\", \"tif\", \"tiff\" };\n        if (rasterExts.Contains(ext))\n        {\n            var bytes = File.ReadAllBytes(path);\n            if (TrySniffContentType(bytes, out var sniffed))\n            {\n                if (!IsCompatible(sniffed, contentType))\n                    throw new ArgumentException(\n                        $\"Image file '{path}' has extension .{ext} but magic bytes indicate {ContentTypeName(sniffed)}. \" +\n                        \"Rename or convert the file.\");","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/ImageSource.cs#L51-L87","documentation":"Thrown by ImageSource.ResolveFile when File.Exists(path) returns false. This is a FileNotFoundException (not ArgumentException), and it fires before any attempt to read the file or validate its contents. The path string is included verbatim in the message to help diagnose typos, relative-path issues, or working-directory mismatches.","triggerScenarios":"Calling ImageSource.Resolve with a local file path that does not exist on disk. This includes: typoed paths, relative paths resolved against the wrong working directory, paths to files that were deleted between the time the command was constructed and when Resolve ran, and paths with incorrect casing on case-sensitive filesystems.","commonSituations":"An agent operating from a different working directory than expected, so a relative path doesn't resolve. A file path captured by a dump command that has since been moved or deleted. A containerized or sandboxed environment where the path is valid on the host but not mounted inside the container. Case-sensitivity issues when moving from Windows to Linux/macOS.","solutions":["Verify the file exists at the exact path with an absolute path (e.g. '/home/user/images/logo.png').","Check the working directory of the process and use an absolute path instead of a relative one.","If the file was recently moved or deleted, restore it or update the path.","On case-sensitive filesystems, ensure the path casing exactly matches the file on disk."],"exampleFix":"// before — relative path fails in unexpected cwd\nadd image src='assets/logo.png' path='/body'\n\n// after — absolute path\nadd image src='/home/user/project/assets/logo.png' path='/body'","handlingStrategy":"validation","validationCode":"// Pre-check file existence before resolving\nif (!File.Exists(path))\n{\n    Console.Error.WriteLine($\"Image file not found: {path}\");\n    return;\n}\nvar (stream, contentType) = ImageSource.Resolve(path);","typeGuard":null,"tryCatchPattern":"try\n{\n    var (stream, contentType) = ImageSource.Resolve(path);\n}\ncatch (FileNotFoundException ex) when (ex.Message.Contains(\"Image file not found\"))\n{\n    // Prompt user for correct path or skip\n}","preventionTips":["Always use absolute paths for image sources to avoid working-directory ambiguity.","Call File.Exists before invoking Resolve to provide your own error context.","In containerized environments, verify the path is mounted before referencing it."],"tags":["image","file-not-found","path-validation","filesystem"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}