slint-ui/slint · error
URL conversion can not fail here
Error message
URL conversion can not fail here
What it means
In `replace_x_as_y_with_newtype`, a source-file path is converted into an `lsp_types::Url` for a TextEdit. The conversion (`Url::from_file_path`) is expected to be infallible here because the path came from an already-valid document URL. Panicking means the stored file path is not a valid file:// URL-convertible path.
Solutions
- Ensure the document was loaded from a real, absolute file path
- Avoid renaming operations on virtual/untitled documents (non-file:// URIs)
- Use `Url::from_file_path(...).ok()?` and skip the edit instead of panicking
- Report the offending path to the Slint LSP maintainers if it is a normal absolute path
Example fix
// before
url_from_path(source_file.path()).expect("URL conversion can not fail here")
// after
match lsp_types::Url::from_file_path(source_file.path()) {
Ok(url) => url,
Err(_) => return None, // skip non-file documents
} Defensive patterns
Strategy: validation
Validate before calling
if !source_file.path().is_absolute() { return None; } // skip virtual/relative paths Type guard
fn to_url(p: &std::path::Path) -> Option<lsp_types::Url> { lsp_types::Url::from_file_path(p).ok() } Try / catch
// if you own the caller
let Ok(url) = lsp_types::Url::from_file_path(path) else { return Ok(None) }; Prevention
- Only run renames on documents with file:// URIs
- Check the URI scheme in your LSP client before requesting rename
- Convert paths to Url at document-load time so failures surface early
When it happens
Trigger: Renaming an `X as Y` type import when `source_file.path()` returns a path that cannot be converted to a URL (non-UTF-8 or non-absolute path, e.g. a virtual/synthetic document).
Common situations: LSP clients opening virtual in-memory documents with non-file schemes; network drives or Windows paths handled oddly; documents loaded from unusual sources.
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
- Identifier is in unknown document
- Child has no stdin
- Child has no stdout
- Callbacks were set up earlier
- Could not find executable name of the slint-lsp
AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16).
Data as JSON: /api/errors/27f3fbc946130c95.
Report an issue: GitHub.
Appendix: source
Thrown at internal/editor-preview/editing/rename_component.rs:199
let start_position = util::text_size_to_lsp_position(
source_file,
x.text_range().start(),
document_cache.format,
);
let end_position = util::text_size_to_lsp_position(
source_file,
y.text_range().end(),
document_cache.format,
);
crate::editing::SingleTextEdit::from_path(
document_cache,
source_file.path(),
lsp_types::TextEdit {
range: lsp_types::Range::new(start_position, end_position),
new_text: new_type.to_string(),
},
)
.expect("URL conversion can not fail here")
}
let ti = query.parent_token_info();
let source_file = type_name.source_file()?;
if i_slint_compiler::parser::normalize_identifier(type_name.text()) == ti.name {
if let Some(renamed_to) = renamed_to {
if i_slint_compiler::parser::normalize_identifier(renamed_to.text())
== i_slint_compiler::parser::normalize_identifier(new_type)
{
if query.has_parent_token_info() {
return query.update_parent_token_info(renamed_to);
}
// `Old as New` => `New`
edits.push(replace_x_as_y_with_newtype(
document_cache,
source_file,View on GitHub (pinned to bb937076de)