{"record":{"id":"20cfabd604725ff3","repo":"BoundaryML/baml","slug":"workspace-url-is-not-a-file-or-directory","errorCode":null,"errorMessage":"Workspace URL is not a file or directory: {:?}","messagePattern":"Workspace URL is not a file or directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_server/src/session.rs","lineNumber":88,"sourceCode":"}\n\nimpl Session {\n    pub fn new(\n        client_capabilities: &ClientCapabilities,\n        position_encoding: PositionEncoding,\n        global_settings: ClientSettings,\n        workspace_folders: &[(Url, ClientSettings)],\n        playground_port: u16,\n        to_webview_router_tx: broadcast::Sender<WebviewRouterMessage>,\n        client_version: Option<String>,\n    ) -> anyhow::Result<Self> {\n        let mut projects = HashMap::new();\n        let index = index::Index::new(global_settings.clone());\n\n        for (url, _) in workspace_folders {\n            let workspace_path = url\n                .to_file_path()\n                .map_err(|()| anyhow!(\"Workspace URL is not a file or directory: {:?}\", url))?;\n\n            // Try to find the baml_src directory\n            if let Some(baml_src) = find_top_level_parent(&workspace_path) {\n                projects.insert(\n                    baml_src.clone(),\n                    Arc::new(Mutex::new(Project::new(BamlProject {\n                        root_dir_name: baml_src.clone(),\n                        files: HashMap::new(),\n                        unsaved_files: HashMap::new(),\n                        cached_runtime: None,\n                    }))),\n                );\n                tracing::info!(\n                    \"Session::new: Added initial project for baml_src path: {:?}\",\n                    baml_src\n                );\n            } else {\n                tracing::info!(\"Session::new: No baml_src found yet {:?}\", workspace_path);","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_server/src/session.rs#L70-L106","documentation":"Session::new builds a Project per workspace folder; url.to_file_path() only succeeds for file:// URLs pointing at files/directories. When a workspace folder URL is not a valid file path (remote/virtual schemes, malformed URI), session creation fails with this error.","triggerScenarios":"Client supplies a workspace folder with a non-file scheme (e.g. untitled:, http:, vscode-remote://) or a malformed URL that cannot be converted to a filesystem path.","commonSituations":"Opening an untitled/unsaved workspace in VS Code; remote development (SSH/WSL/containers) where folders are virtual; clients sending percentage-encoded or malformed workspace URIs.","solutions":["Open a real local folder containing baml_src as the workspace","If using remote development, ensure the server runs on the remote host where the path exists","Check the workspaceFolders URIs the client sends and convert unsupported schemes to local paths where possible","Update the client plugin / server so unsupported schemes are skipped instead of failing the session"],"exampleFix":"// before: failing on virtual scheme\n// untitled:Untitled-1 -> to_file_path() error\n// after: filter before Session::new\nlet folders: Vec<_> = workspace_folders.into_iter().filter(|(u, _)| u.scheme() == \"file\").collect();","handlingStrategy":"validation","validationCode":"const fileFolders = workspaceFolders.filter(f => new URL(f.uri).protocol === 'file:');\nif (fileFolders.length !== workspaceFolders.length) console.warn('non-file workspace folders will fail Session::new');","typeGuard":"function isFileUrl(s: string): boolean { try { return new URL(s).protocol === 'file:'; } catch { return false; } }","tryCatchPattern":"try { await initializeSession(folders); } catch (e) { if (String(e).includes('not a file or directory')) await initializeSession(folders.filter(f => isFileUrl(f.uri))); else throw e; }","preventionTips":["Only pass local file:// folders to the server","Handle untitled/remote workspaces by opening a real folder","Run the server on the host where files live (remote dev)","Validate workspace URIs before initialize"],"tags":["lsp","workspace","url","rust"],"backgroundTag":"invalid-url-format","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}