{"record":{"id":"27f3fbc946130c95","repo":"slint-ui/slint","slug":"url-conversion-can-not-fail-here","errorCode":null,"errorMessage":"URL conversion can not fail here","messagePattern":"URL conversion can not fail here","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/editor-preview/editing/rename_component.rs","lineNumber":199,"sourceCode":"        let start_position = util::text_size_to_lsp_position(\n            source_file,\n            x.text_range().start(),\n            document_cache.format,\n        );\n        let end_position = util::text_size_to_lsp_position(\n            source_file,\n            y.text_range().end(),\n            document_cache.format,\n        );\n        crate::editing::SingleTextEdit::from_path(\n            document_cache,\n            source_file.path(),\n            lsp_types::TextEdit {\n                range: lsp_types::Range::new(start_position, end_position),\n                new_text: new_type.to_string(),\n            },\n        )\n        .expect(\"URL conversion can not fail here\")\n    }\n\n    let ti = query.parent_token_info();\n    let source_file = type_name.source_file()?;\n\n    if i_slint_compiler::parser::normalize_identifier(type_name.text()) == ti.name {\n        if let Some(renamed_to) = renamed_to {\n            if i_slint_compiler::parser::normalize_identifier(renamed_to.text())\n                == i_slint_compiler::parser::normalize_identifier(new_type)\n            {\n                if query.has_parent_token_info() {\n                    return query.update_parent_token_info(renamed_to);\n                }\n\n                // `Old as New` => `New`\n                edits.push(replace_x_as_y_with_newtype(\n                    document_cache,\n                    source_file,","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/internal/editor-preview/editing/rename_component.rs#L181-L217","documentation":"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.","triggerScenarios":"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).","commonSituations":"LSP clients opening virtual in-memory documents with non-file schemes; network drives or Windows paths handled oddly; documents loaded from unusual sources.","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"],"exampleFix":"// before\nurl_from_path(source_file.path()).expect(\"URL conversion can not fail here\")\n\n// after\nmatch lsp_types::Url::from_file_path(source_file.path()) {\n    Ok(url) => url,\n    Err(_) => return None, // skip non-file documents\n}","handlingStrategy":"validation","validationCode":"if !source_file.path().is_absolute() { return None; } // skip virtual/relative paths","typeGuard":"fn to_url(p: &std::path::Path) -> Option<lsp_types::Url> { lsp_types::Url::from_file_path(p).ok() }","tryCatchPattern":"// if you own the caller\nlet Ok(url) = lsp_types::Url::from_file_path(path) else { return Ok(None) };","preventionTips":["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"],"tags":["lsp","url","rename","editor-preview","panic"],"backgroundTag":"invalid-url-format","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}