{"record":{"id":"41f05c6f6143b417","repo":"Kuberwastaken/claurst","slug":"cannot-read-for-lsp","errorCode":null,"errorMessage":"Cannot read '{}' for LSP: {}","messagePattern":"Cannot read '(.+?)' for LSP: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-rust/crates/core/src/lsp.rs","lineNumber":1068,"sourceCode":"        &mut self,\r\n        file_path: &str,\r\n        root_dir: &Path,\r\n    ) -> anyhow::Result<()> {\r\n        let uri = path_to_uri(file_path);\r\n        let server_name = match self.server_name_for_file(file_path) {\r\n            Some(n) => n.to_string(),\r\n            None => return Ok(()),\r\n        };\r\n\r\n        // Skip if already opened on this server\r\n        if self.opened_files.get(&uri).map(|s| s.as_str()) == Some(server_name.as_str()) {\r\n            return Ok(());\r\n        }\r\n\r\n        let content = match tokio::fs::read_to_string(file_path).await {\r\n            Ok(c) => c,\r\n            Err(e) => {\r\n                return Err(anyhow::anyhow!(\r\n                    \"Cannot read '{}' for LSP: {}\",\r\n                    file_path,\r\n                    e\r\n                ))\r\n            }\r\n        };\r\n\r\n        // Ensure the server is running first (borrows self mutably, so must\r\n        // finish before we borrow opened_files).\r\n        self.ensure_started(file_path, root_dir).await?;\r\n\r\n        if let Some(client) = self.clients.get_mut(&server_name) {\r\n            let lang = client.server_config.language_for_file(file_path);\r\n            client.open_document(&uri, &lang, &content).await?;\r\n            self.opened_files.insert(uri, server_name);\r\n        }\r\n        Ok(())\r\n    }\r","sourceCodeStart":1050,"sourceCodeEnd":1086,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/core/src/lsp.rs#L1050-L1086","documentation":"Thrown in `LspManager::open_file` when `tokio::fs::read_to_string(file_path)` fails while loading file content to send as a `textDocument/didOpen` notification. The raw IO error (NotFound, PermissionDenied, invalid UTF-8, etc.) is embedded in the message. The file must be readable as UTF-8 text to be opened on the LSP server.","triggerScenarios":"open_file(file_path, root_dir) is called with a path that does not exist, was deleted, lacks read permission, is a directory, or contains invalid UTF-8 bytes.","commonSituations":"Stale buffer referencing a deleted file; opening binary or non-UTF-8 files; typo in path or wrong working directory; file locked by permissions (e.g. root-owned file, sandboxed environment).","solutions":["Verify the path exists and is a regular file before calling open_file (std::path::Path::is_file).","Check file permissions and that the process user can read it.","Ensure the file is valid UTF-8; skip or convert non-UTF-8 files before LSP open.","Refresh any cached/stale path against the current filesystem."],"exampleFix":"// before: unconditional open\nmanager.open_file(path, root).await?;\n// after: pre-check the file\nlet p = std::path::Path::new(path);\nif p.is_file() {\n    manager.open_file(path, root).await?;\n}","handlingStrategy":"validation","validationCode":"let p = std::path::Path::new(path);\nif !p.is_file() { bail!(\"not a readable file: {path}\"); }\n// optional UTF-8 pre-check\nstd::fs::read(p).and_then(|b| String::from_utf8(b).map_err(|_| io::Error::new(io::ErrorKind::InvalidData, \"not UTF-8\")))?;","typeGuard":"fn openable(path: &str) -> bool {\n    std::path::Path::new(path).is_file()\n}","tryCatchPattern":"match manager.open_file(path, root).await {\n    Ok(()) => {},\n    Err(e) if e.to_string().starts_with(\"Cannot read\") => {\n        tracing::warn!(\"skipping LSP open for unreadable file {path}: {e}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check path existence and type before LSP operations.","Skip binary or non-UTF-8 files when collecting files for LSP.","Re-resolve paths against the working directory; beware deleted/stale buffers."],"tags":["lsp","file-io","rust"],"backgroundTag":"file-read-failed","analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}