{"record":{"id":"aaf317f73e97f46f","repo":"biomejs/biome","slug":"failed-to-convert-path-to-url","errorCode":null,"errorMessage":"failed to convert path to URL: {}","messagePattern":"failed to convert path to URL: (.+?)","errorType":"exception","errorClass":"LspError","httpStatus":null,"severity":"error","filePath":"crates/biome_lsp/src/handlers/navigation.rs","lineNumber":134,"sourceCode":"        let content = session.workspace_for_request().get_file_content(\n            biome_service::workspace::GetFileContentParams {\n                project_key: doc.project_key,\n                path: definition_path.clone(),\n            },\n        )?;\n        let target_line_index = LineIndex::new(&content);\n        to_proto::range(&target_line_index, *definition_range, position_encoding)?\n    };\n\n    Ok(Location {\n        uri: target_uri,\n        range: target_range,\n    })\n}\n\nfn uri_from_path(path: &BiomePath) -> Result<Uri, LspError> {\n    let url = url::Url::from_file_path(path.as_path()).map_err(|_| {\n        LspError::from(anyhow::anyhow!(\n            \"failed to convert path to URL: {}\",\n            path.as_path()\n        ))\n    })?;\n    Uri::from_str(url.as_str())\n        .map_err(|err| LspError::from(anyhow::anyhow!(\"failed to convert URL to URI: {err}\")))\n}\n","sourceCodeStart":116,"sourceCodeEnd":142,"githubUrl":"https://github.com/biomejs/biome/blob/7529811358079edb5a2a9d4a5f67a9f639a63f3a/crates/biome_lsp/src/handlers/navigation.rs#L116-L142","documentation":"Navigation handlers (go-to-definition, type definitions, references) build the target Location by converting the definition's file path into a file:// URL with Url::from_file_path (navigation.rs:132-138). That conversion fails, and this error is returned, when the path cannot be represented as an absolute file URL - a relative path, an empty path, or on Windows a path without a drive/root prefix.","triggerScenarios":"A navigation target resolves to a relative or empty path, e.g. a synthesized or virtual document with no absolute location; on Windows a path lacking a drive letter. Raised from to_location/uri_from_path while answering a textDocument/definition-style request.","commonSituations":"Definitions inside in-memory or untitled documents; monorepos or custom workspace roots where the daemon produces a project-relative path; platform-specific path handling differences between Windows and Unix.","solutions":["Open files in the editor via absolute file:// URIs (save untitled buffers, avoid synthetic relative paths).","Check that the workspace folder / project root given to the Biome LSP server is an absolute path so internal resolution yields absolute paths.","If the file is a real on-disk file and it still fails, capture the path printed in the error and report it upstream, since daemon-produced paths should always be absolute."],"exampleFix":"// before: opening a document with a relative path\nopenDocument(\"src/index.ts\");\n\n// after: open with an absolute file:// URI\nimport { pathToFileURL } from \"node:url\";\nimport path from \"node:path\";\nopenDocument(pathToFileURL(path.resolve(\"src/index.ts\")).href);","handlingStrategy":"validation","validationCode":"// Client-side: always derive document URIs from absolute paths so navigation targets stay absolute\nimport { pathToFileURL } from \"node:url\";\nimport path from \"node:path\";\n\nfunction toAbsoluteFileUri(p) {\n\tconst abs = path.isAbsolute(p) ? p : path.resolve(p);\n\treturn pathToFileURL(abs).href; // file:///... always convertible back by the server\n}","typeGuard":null,"tryCatchPattern":"try {\n\tconst locations = await connection.sendRequest(\"textDocument/definition\", params);\n} catch (err) {\n\tif (String(err?.message ?? err).includes(\"failed to convert path to URL\")) {\n\t\t// target resolved to a relative/virtual path; nothing to navigate to\n\t\treturn [];\n\t}\n\tthrow err;\n}","preventionTips":["Open and analyze files through absolute file:// URIs; save untitled/virtual buffers first.","Configure the Biome server with an absolute workspace root so internal paths resolve absolutely.","On Windows, ensure paths include the drive prefix before they reach the server."],"tags":["lsp","navigation","path","url","filesystem"],"backgroundTag":"file-path-to-url-conversion","analyzedSha":"7529811358079edb5a2a9d4a5f67a9f639a63f3a","analyzedAt":"2026-08-16T22:13:27.842Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}