{"record":{"id":"48d20159705d1061","repo":"LykosAI/StabilityMatrix","slug":"image-file-does-not-exist","errorCode":null,"errorMessage":"Image file does not exist","messagePattern":"Image file does not exist","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Models/ImageSource.cs","lineNumber":233,"sourceCode":"        return guid;\n    }\n\n    /// <summary>\n    /// Return a file name with Guid from Blake3 hash\n    /// This will throw if the Blake3 hash has not been calculated yet\n    /// </summary>\n    public string GetHashGuidFileNameCached()\n    {\n        // Calculate hash if not available\n        if (contentHashBlake3 is null)\n        {\n            // Local file\n            if (LocalFile is not null)\n            {\n                // File must exist\n                if (!LocalFile.Exists)\n                {\n                    throw new FileNotFoundException(\"Image file does not exist\", LocalFile);\n                }\n\n                // Fail in debug since hash should have been pre-calculated\n                Debug.Fail(\"Hash has not been calculated when GetHashGuidFileNameCached() was called\");\n\n                var data = LocalFile.ReadAllBytes();\n                contentHashBlake3 = FileHash.GetBlake3Parallel(data);\n            }\n            // Bitmap\n            else if (Bitmap is not null)\n            {\n                var data = Bitmap.ToByteArray();\n                contentHashBlake3 = FileHash.GetBlake3Parallel(data);\n            }\n            else\n            {\n                throw new InvalidOperationException(\"ImageSource is not a local file or bitmap\");\n            }","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Models/ImageSource.cs#L215-L251","documentation":"GetHashGuidFileNameCached() builds a content-hash-based GUID file name for the image. When the ImageSource wraps a local file, the code asserts the file exists before hashing; if LocalFile.Exists is false it throws FileNotFoundException with the missing path. The library requires an existing, readable file because the hash is computed from the file's bytes.","triggerScenarios":"Calling GetHashGuidFileNameCached() on an ImageSource constructed with a LocalFile whose path no longer exists (file deleted, moved, or path constructed before the file was written).","commonSituations":"Image was deleted or renamed between acquisition and hashing; referencing an output image from a previous generation that was cleaned up; path built from stale metadata; running on a different machine/drive where the relative path is invalid.","solutions":["Check LocalFile.Exists (or File.Exists on the path) before calling GetHashGuidFileNameCached and skip or refresh the ImageSource if false.","Re-create the ImageSource from a path that currently exists on disk.","If the file is produced asynchronously, await its completion before hashing.","Wrap the call in try/catch for FileNotFoundException and fall back to a placeholder or re-scan."],"exampleFix":"// before\nvar name = imageSource.GetHashGuidFileNameCached();\n// after\nif (imageSource.LocalFile is { Exists: true })\n{\n    var name = imageSource.GetHashGuidFileNameCached();\n}\nelse\n{\n    // regenerate, rescan, or skip this image\n}","handlingStrategy":"validation","validationCode":"if (imageSource.LocalFile is { } f && !f.Exists)\n{\n    throw new FileNotFoundException($\"Image missing before hashing: {f.FullName}\");\n}","typeGuard":"bool Hashable(ImageSource s) => s.LocalFile is { Exists: true } || s.Bitmap is not null;","tryCatchPattern":"try { var name = img.GetHashGuidFileNameCached(); }\ncatch (FileNotFoundException ex) { log.Warn($\"Image vanished: {ex.FileName}\"); SkipOrRefresh(img); }","preventionTips":["Hash images immediately after generation while the file is guaranteed to exist.","Hold a FileInfo obtained from an actual File.Exists check, not a stale path string.","Do not delete output images while other components still hold ImageSource references."],"tags":["file-not-found","image","hashing"],"backgroundTag":"file-not-found","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}