{"record":{"id":"d8edb721728b28c2","repo":"biomejs/biome","slug":"failed-to-convert-url-to-uri-err","errorCode":null,"errorMessage":"failed to convert URL to URI: {err}","messagePattern":"failed to convert URL to URI: (.+?)","errorType":"exception","errorClass":"LspError","httpStatus":null,"severity":"error","filePath":"crates/biome_lsp/src/handlers/navigation.rs","lineNumber":140,"sourceCode":"        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":122,"sourceCodeEnd":142,"githubUrl":"https://github.com/biomejs/biome/blob/7529811358079edb5a2a9d4a5f67a9f639a63f3a/crates/biome_lsp/src/handlers/navigation.rs#L122-L142","documentation":"Second stage of uri_from_path: after Url::from_file_path succeeds, the URL string is re-parsed into the tower-lsp Uri type with Uri::from_str (navigation.rs:139-140). This fails only when the constructed file:// URL violates the stricter Uri grammar - for example unusual percent-encoding sequences or characters the url crate accepts but the Uri parser rejects. It shares its parent function with error [8] and aborts the same navigation requests.","triggerScenarios":"A file path containing byte sequences that survive Url::from_file_path but fail Uri::from_str: exotic escape sequences, malformed percent-encoding introduced elsewhere, or non-standard path shapes on the platform.","commonSituations":"Rare; usually exotic filenames or a path-construction bug upstream. Normal spaces and unicode are percent-encoded by the url crate and parse fine.","solutions":["Inspect the failing file path (from the surrounding navigation request or logs) for unusual characters or escape sequences and rename/normalize the file.","Verify no tooling rewrote the path (e.g. shell escaping producing literal % sequences in the filename).","Report upstream to Biome with the exact path, since a URL produced by Url::from_file_path should always be parseable as a Uri."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Client-side: reject filenames that would need unusual escaping before the server ever sees them\nfunction isSafeFileName(name) {\n\treturn !/[%\\u0000-\\u001f]/.test(name); // avoid %-sequences and control chars in file names\n}\n\nif (!isSafeFileName(fileName)) {\n\tthrow new Error(`rename ${fileName}: contains characters that break URI round-trips`);\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 URL to URI\")) {\n\t\t// exotic path encoding; skip navigation for this target rather than crashing\n\t\treturn [];\n\t}\n\tthrow err;\n}","preventionTips":["Avoid literal percent signs and control characters in file names; they can produce encoding the Uri parser rejects.","Do not let tooling write shell-escaped strings into file names (e.g. literal %20 in a name).","If it reproduces, capture the exact path and report it upstream; server-generated file:// URLs should always parse as Uri."],"tags":["lsp","navigation","uri","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"}