{"record":{"id":"2e05942d6cd2fa35","repo":"xai-org/grok-build","slug":"file-not-found","errorCode":null,"errorMessage":"File not found","messagePattern":"File not found","errorType":"exception","errorClass":"FsError","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/file_system/mock_fs.rs","lineNumber":29,"sourceCode":"}\n\n#[async_trait::async_trait]\nimpl AsyncFileSystem for MockFs {\n    fn root(&self) -> &Path {\n        &self.root\n    }\n\n    async fn exists(&self, path: &Path) -> Result<bool, FsError> {\n        let map = self.files.read().await;\n        Ok(map.contains_key(path))\n    }\n\n    async fn read_file(&self, path: &Path) -> Result<Vec<u8>, FsError> {\n        let map = self.files.read().await;\n        if let Some(bytes) = map.get(path) {\n            Ok(bytes.clone())\n        } else {\n            Err(io::Error::new(io::ErrorKind::NotFound, \"File not found\").into())\n        }\n    }\n\n    async fn try_read_file(&self, path: &Path) -> Result<Option<Vec<u8>>, FsError> {\n        let map = self.files.read().await;\n        Ok(map.get(path).cloned())\n    }\n\n    async fn write_file(&self, path: &Path, data: &[u8]) -> Result<(), FsError> {\n        let mut map = self.files.write().await;\n        map.insert(path.to_path_buf(), data.to_vec());\n        Ok(())\n    }\n\n    async fn delete_file(&self, path: &Path) -> Result<(), FsError> {\n        let mut map = self.files.write().await;\n        map.remove(path);\n        Ok(())","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/file_system/mock_fs.rs#L11-L47","documentation":"MockFileSystem is an in-memory FileSystem implementation backed by a HashMap of paths to bytes. read_file looks the path up in that map and, if absent, converts a std io::Error of kind NotFound with message 'File not found' into an FsError — mirroring a real filesystem's ENOENT.","triggerScenarios":"Calling read_file on a MockFileSystem for a path that was never inserted via the write/create API, or inserted under a different (non-identical) path — the map is keyed by exact Path, so separators, case, or a missing prefix cause a miss.","commonSituations":"Unit tests that forget to seed the mock before reading; tests writing with one path form (relative) and reading with another (absolute); typos or trailing separators in test paths; relying on a file another test was supposed to create.","solutions":["Insert the file into the mock before reading (call the mock's write_file/create API with the exact same Path).","Normalize paths (absolute, canonical form) when writing and reading in tests.","If the read is expected to sometimes miss, use try_read_file which returns Ok(None) instead of erroring.","Fix the test path spelling/separator to match the key used at write time."],"exampleFix":"// before\nlet data = fs.read_file(&Path::new(\"/tmp/a.txt\")).await?; // never seeded\n// after\nfs.write_file(&Path::new(\"/tmp/a.txt\"), b\"hello\").await?;\nlet data = fs.read_file(&Path::new(\"/tmp/a.txt\")).await?;","handlingStrategy":"try-catch","validationCode":"async fn mock_has(fs: &MockFileSystem, path: &Path) -> bool {\n    fs.try_read_file(path).await.map(|o| o.is_some()).unwrap_or(false)\n}\n// seed or skip if false","typeGuard":null,"tryCatchPattern":"match fs.read_file(&path).await {\n    Ok(bytes) => bytes,\n    Err(e) if matches!(&*e, FsError::Io(io) if io.kind() == std::io::ErrorKind::NotFound) => {\n        Vec::new() // or seed and retry in test\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Seed the mock with the exact same Path used at read time","Normalize paths (absolute, consistent separators) in test fixtures","Prefer try_read_file when absence is a valid outcome"],"tags":["testing","mock","filesystem","not-found"],"backgroundTag":"file-not-found","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}