BoundaryML/baml · error
InternalError
InternalError
Error message
Could not convert url to path {}: {e:?} What it means
`DocumentKey::from_url` converts an LSP document URL into a filesystem path via `Url::to_file_path()`; if the URL is not a valid `file://` URL convertible to a path, this InternalError is raised with the offending URL. The LSP client sent a URI the server cannot map onto the workspace filesystem.
Source
Thrown at engine/language_server/src/edit.rs:78
// Ensure our relative path doesn't begin with a path separator.
let relative_path = relative_path
.strip_prefix(std::path::MAIN_SEPARATOR_STR)
.unwrap_or(relative_path);
let absolute_path = root_path.join(relative_path);
// let aboslute_url = Url::from_file_path(absolute_path)
// .map_err(|_| anyhow::anyhow!("Could not convert path to URL"))?;
Ok(DocumentKey(absolute_path))
}
/// A flexible constructor that can take any URL delivered by the LSP.
/// It uses the same logic as `DocumentKey::from_path`.
pub fn from_url(root_path: &Path, url: &Url) -> anyhow::Result<Self> {
Self::from_path(
root_path,
&PathBuf::from(
&url.to_file_path()
.map_err(|e| anyhow::anyhow!("Could not convert url to path {}: {e:?}", url))?,
),
)
}
pub fn unchecked_to_string(&self) -> String {
self.0
.as_os_str()
.to_str()
.expect("TODO: Assumed valid string")
.to_string()
}
}
impl std::fmt::Display for DocumentKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// TODO: Fix.
let str = format!("{:?}", self.0);
str.fmt(f)View on GitHub (pinned to bd85ce9dee)
Solutions
- Check the URI in the error and confirm it uses the file:// scheme and points inside the workspace.
- Exclude virtual/untitled documents from being treated as BAML files (open them as plain text).
- Upgrade the LSP client/extension if it sends malformed URIs.
- If working remotely, ensure the language server runs in the same filesystem context as the URIs.
Example fix
// problematic URI sent by client untitled:Untitled-1 // expected file:///home/user/project/baml_src/main.baml
Defensive patterns
Strategy: type-guard
Type guard
fn is_local_file_url(url: &Url) -> bool {
url.scheme() == "file" && url.to_file_path().is_ok()
} Try / catch
if !is_local_file_url(url) {
tracing::warn!("skipping non-file document: {url}");
return Ok(None);
} Prevention
- Only send file:// URIs to the BAML language server.
- Exclude untitled/virtual documents from BAML processing.
- Run the server in the same filesystem context that owns the URIs.
When it happens
Trigger: A request (did_open, did_change, hover, etc.) supplies a `Url` that `to_file_path()` rejects — non-file schemes (untitled:, http:, virtual docs), percent-encoding edge cases, or a URL not representing a local path.
Common situations: Editor extensions opening virtual/untitled documents; remote or containerized editors producing non-file URIs; clients sending improperly encoded URIs on Windows.
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
- Path is invalid: {}: {message}
- -32603
- Failed to update runtime: {e}
- Failed to generate a runtime: {e}
- InternalError
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/3b3b945af7ebe888.
Report an issue: GitHub.