{"record":{"id":"c082264913149e0e","repo":"DevToys-app/DevToys","slug":"unable-to-find-the-indicated-file-c08226","errorCode":null,"errorMessage":"Unable to find the indicated file.","messagePattern":"Unable to find the indicated file\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/app/dev/platforms/desktop/DevToys.MacOS/Core/FileStorage.cs","lineNumber":33,"sourceCode":"    {\n        if (!Path.IsPathRooted(relativeOrAbsoluteFilePath))\n        {\n            relativeOrAbsoluteFilePath = Path.Combine(AppCacheDirectory, relativeOrAbsoluteFilePath);\n        }\n\n        return File.Exists(relativeOrAbsoluteFilePath);\n    }\n\n    public FileStream OpenReadFile(string relativeOrAbsoluteFilePath)\n    {\n        if (!Path.IsPathRooted(relativeOrAbsoluteFilePath))\n        {\n            relativeOrAbsoluteFilePath = Path.Combine(AppCacheDirectory, relativeOrAbsoluteFilePath);\n        }\n\n        if (!File.Exists(relativeOrAbsoluteFilePath))\n        {\n            throw new FileNotFoundException(\"Unable to find the indicated file.\", relativeOrAbsoluteFilePath);\n        }\n\n        return new FileStream(relativeOrAbsoluteFilePath, FileMode.Open, FileAccess.Read, FileShare.Read,\n            SandboxedFileReader.BufferSize, FileOptions.Asynchronous | FileOptions.SequentialScan);\n    }\n\n    public FileStream OpenWriteFile(string relativeOrAbsoluteFilePath, bool replaceIfExist)\n    {\n        if (!Path.IsPathRooted(relativeOrAbsoluteFilePath))\n        {\n            relativeOrAbsoluteFilePath = Path.Combine(AppCacheDirectory, relativeOrAbsoluteFilePath);\n        }\n\n        if (File.Exists(relativeOrAbsoluteFilePath) && replaceIfExist)\n        {\n            File.Delete(relativeOrAbsoluteFilePath);\n        }\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/DevToys-app/DevToys/blob/7e12df8448aa1f6aec4a8736b3e06a1c90530715/src/app/dev/platforms/desktop/DevToys.MacOS/Core/FileStorage.cs#L15-L51","documentation":"Thrown by DevToys.MacOS FileStorage.OpenReadFile after resolving a relative path against AppCacheDirectory and finding the file absent via File.Exists. It is the MacOS platform's implementation of the shared IFileStorage.OpenReadFile contract. FileNotFoundException carries the resolved absolute path.","triggerScenarios":"Calling IFileStorage.OpenReadFile with a relative path that does not exist under AppCacheDirectory; an absolute path to a missing file; a file removed between the existence check and the open (TOCTOU); a sandboxed app trying to read outside its container without entitlement.","commonSituations":"App sandbox container path changed across launches; a file the app expected to find in its cache/ was evicted; a path from a security-scoped bookmark whose resource is gone; producer step failed so the file was never written.","solutions":["Call IFileStorage.FileExists(path) right before OpenReadFile and branch on the result.","Inspect the resolved path (AppCacheDirectory + relative) to confirm it is inside the expected container.","For security-scoped resources, start accessing the security-scoped bookmark before reading.","Ensure OpenWriteFile completed and the file was flushed/closed before reading.","Catch FileNotFoundException and recover (recreate, reprompt, skip)."],"exampleFix":"// before\nusing FileStream stream = fileStorage.OpenReadFile(relativePath);\n\n// after\nif (!fileStorage.FileExists(relativePath))\n{\n    return; // or recreate / reprompt\n}\nusing FileStream stream = fileStorage.OpenReadFile(relativePath);","handlingStrategy":"validation","validationCode":"string resolved = Path.IsPathRooted(path) ? path : Path.Combine(fileStorage.AppCacheDirectory, path);\nif (!File.Exists(resolved))\n{\n    return; // or recreate / reprompt\n}\nusing FileStream stream = fileStorage.OpenReadFile(path);","typeGuard":null,"tryCatchPattern":"try\n{\n    using FileStream stream = fileStorage.OpenReadFile(path);\n}\ncatch (FileNotFoundException ex)\n{\n    // expected missing file — recreate or skip\n}","preventionTips":["Precede OpenReadFile with FileExists; on MacOS also confirm the path is inside the sandbox container or a valid security-scoped resource.","For security-scoped bookmarks, call StartAccessingSecurityScopedResource before reading and stop after.","Log the resolved path so missing files are easy to diagnose across launches.","Ensure OpenWriteFile completed before the consumer reads."],"tags":["csharp","file-io","filestorage","macos","toctou"],"backgroundTag":null,"analyzedSha":"7e12df8448aa1f6aec4a8736b3e06a1c90530715","analyzedAt":"2026-08-13T10:27:33.924Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}