{"record":{"id":"0e5ea163d74913ef","repo":"DevToys-app/DevToys","slug":"unable-to-find-the-indicated-file","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.CLI/Core/FileStorage/FileStorage.cs","lineNumber":37,"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, 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\n        string parentDirectory = Path.GetDirectoryName(relativeOrAbsoluteFilePath)!;","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/DevToys-app/DevToys/blob/7e12df8448aa1f6aec4a8736b3e06a1c90530715/src/app/dev/platforms/desktop/DevToys.CLI/Core/FileStorage/FileStorage.cs#L19-L55","documentation":"Thrown by DevToys.CLI FileStorage.OpenReadFile after it resolves a relative path against AppCacheDirectory (Constants.AppCacheDirectory) and then finds the file missing via File.Exists. It is a deliberate FileNotFoundException with the resolved path as the fileName argument. The same IFileStorage.OpenReadFile contract is implemented identically by the Linux, MacOS, and Windows desktop platforms, so this error class is platform-wide.","triggerScenarios":"Calling IFileStorage.OpenReadFile(relativeOrAbsoluteFilePath) where the file was never written, was written to a different AppCacheDirectory, or was deleted between a FileExists check and the open (TOCTOU); passing a relative path that resolves under the wrong cache root; case-sensitivity mismatch on Linux.","commonSituations":"A tool extension reads a cache/temp file it expects another step to have created; the app cache dir was cleared or relocated; the path uses backslashes/forward slashes that resolve differently per OS; a previous OpenWriteFile failed silently so the read finds nothing.","solutions":["Call IFileStorage.FileExists(path) immediately before OpenReadFile and branch on the result.","Log/inspect the resolved path (AppCacheDirectory + relative) to confirm it points where you expect.","Ensure any producer step (OpenWriteFile) actually completed and flushed before the consumer reads.","On case-sensitive filesystems, verify the path casing matches the file on disk.","Wrap the call in try/catch (FileNotFoundException) and degrade gracefully (recreate, reprompt, skip)."],"exampleFix":"// before\nusing FileStream stream = fileStorage.OpenReadFile(relativePath);\n\n// after\nif (!fileStorage.FileExists(relativePath))\n{\n    // recreate / reprompt / log and abort\n    return;\n}\nusing FileStream stream = fileStorage.OpenReadFile(relativePath);","handlingStrategy":"validation","validationCode":"// Call before IFileStorage.OpenReadFile to avoid the throw.\nstring resolved = Path.IsPathRooted(path) ? path : Path.Combine(fileStorage.AppCacheDirectory, path);\nif (!File.Exists(resolved))\n{\n    // file is not there — recreate / reprompt / abort\n    return;\n}\nusing FileStream stream = fileStorage.OpenReadFile(path);","typeGuard":null,"tryCatchPattern":"try\n{\n    using FileStream stream = fileStorage.OpenReadFile(path);\n    // ... read\n}\ncatch (FileNotFoundException ex) when (ex.FileName == path || ex.FileName == resolved)\n{\n    // expected missing cache file — recreate or skip gracefully\n}","preventionTips":["Always pair OpenReadFile with a preceding FileExists check; treat the pair as one contract.","Log the resolved path (AppCacheDirectory + relative) so missing-file reports are debuggable.","Ensure the producer (OpenWriteFile) succeeds and the stream is closed before any consumer reads.","On case-sensitive filesystems, keep the exact on-disk casing in stored paths."],"tags":["csharp","file-io","filestorage","toctou","cross-platform"],"backgroundTag":null,"analyzedSha":"7e12df8448aa1f6aec4a8736b3e06a1c90530715","analyzedAt":"2026-08-13T10:27:33.924Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}