{"record":{"id":"1e3ef118f9017bba","repo":"BoundaryML/baml","slug":"failed-to-gather-files-from-directory","errorCode":null,"errorMessage":"Failed to gather files from directory {}: {}","messagePattern":"Failed to gather files from directory (.+?): (.+?)","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/language_server/src/baml_project/mod.rs","lineNumber":270,"sourceCode":"    pub fn update_file(&mut self, document_key: &DocumentKey, content: Option<String>) {\n        tracing::debug!(\n            \"Updating file: {}, {}\",\n            document_key.path().display(),\n            content.clone().unwrap_or(\"None\".to_string())\n        );\n        if let Some(content) = content {\n            let text_document = TextDocument::new(content, 0);\n            self.files.insert(document_key.clone(), text_document);\n        } else {\n            self.files.remove(document_key);\n        }\n        self.cached_runtime = None;\n    }\n\n    /// Load files into the current state. Also return the newly loaded files.\n    pub fn load_files(&mut self) -> anyhow::Result<HashMap<DocumentKey, TextDocument>> {\n        let workspace_file_paths = gather_files(&self.root_dir_name, false).map_err(|e| {\n            anyhow::anyhow!(\n                \"Failed to gather files from directory {}: {}\",\n                self.root_dir_name.display(),\n                e\n            )\n        })?;\n        let workspace_files = workspace_file_paths\n            .into_iter()\n            .map(|file_path| {\n                let document_key = DocumentKey::from_path(&self.root_dir_name, &file_path)\n                    .map_err(|e| {\n                        anyhow::anyhow!(\n                            \"Failed to create document key for file {}: {}\",\n                            file_path.display(),\n                            e\n                        )\n                    })?;\n                let contents = std::fs::read_to_string(&file_path).map_err(|e| {\n                    anyhow::anyhow!(\"Failed to read file {}: {}\", file_path.display(), e)","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_server/src/baml_project/mod.rs#L252-L288","documentation":"BamlProject.load_files wraps gather_files() failures in this message, which includes the project root directory and the underlying error. It means the language server could not enumerate the BAML/workspace files under root_dir_name, so the project state cannot be loaded. Typically the root directory is missing, inaccessible, or unreadable.","triggerScenarios":"load_files() called when the project root directory does not exist, was deleted or renamed, lacks read permission, or when the filesystem walk (gather_files) fails with an I/O error.","commonSituations":"LSP client sending a didOpen/initialize with a stale workspace root path; project checked out to a different location; symlinked or network-mounted directories that are unavailable; permission changes after checkout.","solutions":["Verify the workspace root directory passed at initialization exists and is readable (ls it from the same user the LSP runs as)","Reopen/restart the editor session so the LSP re-initializes with the correct root_uri","Fix directory permissions (chmod/chown) or move the project back to the expected path","Update any configured workspace root path to the current project location"],"exampleFix":"// before\nlsp.initialize({ rootUri: \"file:///home/me/old-project\" });\n// after\nlsp.initialize({ rootUri: \"file:///home/me/current-project\" });","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn ensure_root_readable(root: &Path) -> std::io::Result<()> {\n    let meta = std::fs::metadata(root)?;\n    if !meta.is_dir() {\n        return Err(std::io::Error::new(std::io::ErrorKind::Other, \"root is not a directory\"));\n    }\n    std::fs::read_dir(root).map(|_| ())\n}","typeGuard":null,"tryCatchPattern":"match project.load_files() {\n    Err(e) if e.to_string().starts_with(\"Failed to gather files\") => {\n        eprintln!(\"Workspace root missing/unreadable: {e}\");\n        // prompt user to re-initialize with correct root\n    }\n    r => r,\n}","preventionTips":["Validate the workspace root exists and is readable before initializing the LSP/project","Avoid pointing the project at network mounts or removable drives that can disappear","Re-initialize editor sessions after moving or renaming the project directory"],"tags":["rust","language-server","filesystem","directory"],"backgroundTag":"directory-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}