BoundaryML/baml · error

Workspace URL is not a file or directory: {:?}

Error message

Workspace URL is not a file or directory: {:?}

What it means

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.

Source

Thrown at engine/language_server/src/session.rs:88

}

impl Session {
    pub fn new(
        client_capabilities: &ClientCapabilities,
        position_encoding: PositionEncoding,
        global_settings: ClientSettings,
        workspace_folders: &[(Url, ClientSettings)],
        playground_port: u16,
        to_webview_router_tx: broadcast::Sender<WebviewRouterMessage>,
        client_version: Option<String>,
    ) -> anyhow::Result<Self> {
        let mut projects = HashMap::new();
        let index = index::Index::new(global_settings.clone());

        for (url, _) in workspace_folders {
            let workspace_path = url
                .to_file_path()
                .map_err(|()| anyhow!("Workspace URL is not a file or directory: {:?}", url))?;

            // Try to find the baml_src directory
            if let Some(baml_src) = find_top_level_parent(&workspace_path) {
                projects.insert(
                    baml_src.clone(),
                    Arc::new(Mutex::new(Project::new(BamlProject {
                        root_dir_name: baml_src.clone(),
                        files: HashMap::new(),
                        unsaved_files: HashMap::new(),
                        cached_runtime: None,
                    }))),
                );
                tracing::info!(
                    "Session::new: Added initial project for baml_src path: {:?}",
                    baml_src
                );
            } else {
                tracing::info!("Session::new: No baml_src found yet {:?}", workspace_path);

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Open a real local folder containing baml_src as the workspace
  2. If using remote development, ensure the server runs on the remote host where the path exists
  3. Check the workspaceFolders URIs the client sends and convert unsupported schemes to local paths where possible
  4. Update the client plugin / server so unsupported schemes are skipped instead of failing the session

Example fix

// before: failing on virtual scheme
// untitled:Untitled-1 -> to_file_path() error
// after: filter before Session::new
let folders: Vec<_> = workspace_folders.into_iter().filter(|(u, _)| u.scheme() == "file").collect();
Defensive patterns

Strategy: validation

Validate before calling

const fileFolders = workspaceFolders.filter(f => new URL(f.uri).protocol === 'file:');
if (fileFolders.length !== workspaceFolders.length) console.warn('non-file workspace folders will fail Session::new');

Type guard

function isFileUrl(s: string): boolean { try { return new URL(s).protocol === 'file:'; } catch { return false; } }

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/20cfabd604725ff3. Report an issue: GitHub.