facebook/flow · error

convert_to_server_uris: invalid file url

Error message

convert_to_server_uris: invalid file url

What it means

Panics when lsp_uri_to_path returns Err while rewriting client URIs to server (canonicalized) URIs for an incoming LSP request. The helper accepts scheme-less strings as paths, handles file: via file_url::parse, and errors for any other scheme (untitled:, http:, vscode-remote:, git:) or a file: URL that fails to parse (bad percent-encoding, malformed host form).

Source

Thrown at rust_port/crates/flow_lsp_server/src/flow_lsp.rs:1214

                    #[allow(clippy::arc_with_non_send_sync)]
                    let mapper = std::sync::Arc::new(mapper);
                    let server_mapper = lsp_prot::default_message_from_server_mapper(mapper);
                    Event::ServerMessage((server_mapper.of_message_from_server)(
                        &server_mapper,
                        msg,
                    ))
                }
                Event::ClientMessage(msg, metadata) => Event::ClientMessage(msg, metadata),
                Event::Tick => Event::Tick,
            }
        }
    }
}

fn convert_to_server_uris(request: lsp_prot::Request) -> lsp_prot::Request {
    let server_uri_of_client_uri = |uri: DocumentUri| -> DocumentUri {
        let path =
            lsp_helpers::lsp_uri_to_path(&uri).expect("convert_to_server_uris: invalid file url");
        let path = FilePath::from(path);
        let canonical = flow_common::files::cached_canonicalize(&path).unwrap_or(path);
        let canonical = canonical.to_string_lossy();
        lsp_helpers::path_to_lsp_uri(canonical.as_ref(), "")
    };
    let mut client_to_server_mapper = lsp_mapper::default_mapper();
    client_to_server_mapper.of_document_uri =
        Box::new(move |_mapper, uri| server_uri_of_client_uri(uri));
    match request {
        lsp_prot::Request::Subscribe => lsp_prot::Request::Subscribe,
        lsp_prot::Request::LspToServer(msg) => {
            let mapped = (client_to_server_mapper.of_lsp_message)(&client_to_server_mapper, msg);
            lsp_prot::Request::LspToServer(mapped)
        }
        lsp_prot::Request::LiveErrorsRequest(uri) => {
            let mapped_uri =
                (client_to_server_mapper.of_document_uri)(&client_to_server_mapper, uri);
            lsp_prot::Request::LiveErrorsRequest(mapped_uri)

View on GitHub (pinned to 5c86586199)

Solutions

  1. Check the URI scheme before conversion and skip/answer empty for non-file: URIs
  2. Fix the client/editor plugin so it only sends file: document URIs to the server
  3. Wrap canonicalization failures with cached_canonicalize's fallback (unwrap_or(path)) instead of panicking on unparseable file URLs

Example fix

// before
let path = lsp_helpers::lsp_uri_to_path(&uri)
    .expect("convert_to_server_uris: invalid file url");

// after — pass non-file URIs through untouched
let path = match lsp_helpers::lsp_uri_to_path(&uri) {
    Ok(path) => FilePath::from(path),
    Err(_) => return uri, // untitled:/virtual docs: leave the URI as-is
};
Defensive patterns

Strategy: validation

Validate before calling

// Only canonicalize real file documents; pass others through
let uri_str = uri.as_str();
if !uri_str.starts_with("file:") {
    return uri; // untitled:/virtual documents: leave untouched
}
let path = lsp_helpers::lsp_uri_to_path(&uri)?; // now safe to require

Type guard

fn is_file_uri(uri: &lsp_types::Url) -> bool {
    uri.scheme().eq_ignore_ascii_case("file")
}

Prevention

When it happens

Trigger: An editor sends a request whose TextDocumentIdentifier references an unsaved buffer (untitled: scheme), a virtual/webview document, or a remote scheme; a client sends a file: URI with invalid encoding; plugins issuing requests over custom schemes.

Common situations: Users running commands on untitled scratch buffers; VS Code remote/webview URIs (vscode-remote:, vscode-userdata:); Jupyter/virtual documents in editors driving the Flow language server.

Related errors


AI-assisted analysis of facebook/flow@5c86586199 (2026-08-20). Data as JSON: /api/errors/51f04becffc3d59e. Report an issue: GitHub.