slint-ui/slint · error
just added if missing
Error message
just added if missing
What it means
This panic comes from an `.expect()` on a HashMap `get_mut` inside `apply_workspace_edit` in the LSP text-editing pipeline. The editor for a document URI is inserted into the `processing` map immediately before lookup, so a miss is an impossible-by-construction state: the URI key was mutated between insert and fetch, or the insertion branch was skipped (e.g. `TextEditor::new` path changed) while the fetch still runs. It is an internal invariant violation, not something a caller can influence through the LSP protocol.
Solutions
- Re-run the LSP operation; a single hiccup in document tracking usually clears on the next edit request
- Update the Slint LSP to the latest version — this panic indicates an internal bug likely fixed upstream
- File a bug with the workspace edit request that triggered it (contents of the edit and document URI)
- As a workaround, save and reopen the affected file so the server rebuilds its document cache
Example fix
// before
processing
.get_mut(&doc.uri)
.expect("just added if missing")
.apply(edit, document_cache.format)?;
// after
let editor = processing
.get_mut(&doc.uri)
.ok_or_else(|| anyhow::anyhow!("no editor registered for {}", doc.uri))?;
editor.apply(edit, document_cache.format)?; Defensive patterns
Strategy: validation
Validate before calling
assert!(processing.contains_key(&doc.uri), "editor must be registered before apply");
Try / catch
// Rust panics cannot be caught without catch_unwind; fix the invariant instead
match processing.get_mut(&doc.uri) {
Some(editor) => editor.apply(edit, document_cache.format)?,
None => return Err(anyhow::anyhow!("missing editor for {}", doc.uri)),
} Prevention
- Always insert into the map in the same iteration as the lookup (use the entry() API)
- Never assume insert-then-get invariants survive refactors — use `.entry(uri)` to fuse them
- Cover the edit-apply loop with a test that exercises a missing-document edge case
When it happens
Trigger: Applying a `workspace/applyEdit` (or document edit) request when the `processing` map entry for `doc.uri` was not inserted on the preceding iteration because the code path that creates `TextEditor::new(document_node.source_file.clone())` did not run for that URI, yet the code still reaches the unconditional `get_mut(&doc.uri)`.
Common situations: Occur only after a refactor of the insert/lookup loop in `apply_workspace_edit`; hit by LSP users when the server processes edits for a document whose source-file node mapping changed (e.g. after a document close/reopen race or stale document cache).
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- EditorSession must have at least one preview
- Global was just valid
- Index was tested to be valid
- index was tested to be valid
- Length was checked
AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16).
Data as JSON: /api/errors/028f7e688ea6cf30.
Report an issue: GitHub.
Appendix: source
Thrown at internal/editor-preview/editing/text_edit.rs:269
) -> crate::Result<Vec<EditedText>> {
let mut processing = HashMap::new();
for (doc, edit) in EditIterator::new(workspace_edit) {
// This is ugly but necessary since the constructor might error out:-/
if !processing.contains_key(&doc.uri) {
let Some(document) = document_cache.get_document(&doc.uri) else {
continue;
};
let Some(document_node) = &document.node else {
continue;
};
let editor = TextEditor::new(document_node.source_file.clone())?;
processing.insert(doc.uri.clone(), editor);
}
processing
.get_mut(&doc.uri)
.expect("just added if missing")
.apply(edit, document_cache.format)?;
}
Ok(processing
.drain()
.filter_map(|(url, v)| {
let edit_result = v.finalize()?;
Some(EditedText { url, contents: edit_result.0 })
})
.collect())
}
/// Given a WorkspaceEdit, return a reversed version of it (that undoes it)
/// Returns none if it cannot be reverted (eg, if it deletes files)
pub fn reversed_edit(
document_cache: &crate::DocumentCache,
edit: &lsp_types::WorkspaceEdit,
) -> Option<lsp_types::WorkspaceEdit> {View on GitHub (pinned to bb937076de)