From 92f128ebb0996d162eb01cb85248509d276da1ef Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 19 Feb 2025 00:52:23 +0200 Subject: [PATCH] Do not fail hard on selection persistence if the editor is removed (#25120) Follow-up of https://github.com/zed-industries/zed/pull/25083 Follows practices from editors' scroll position persisting: https://github.com/zed-industries/zed/blob/5a05b7461e476d7ddc59418868ebdab6687b8d2f/crates/editor/src/persistence.rs#L200 and do not fail hard if the editor with the ID given does not exist. Also add the problematic IDs into the error context to see them in the error logs. Release Notes: - N/A --- crates/editor/src/editor.rs | 2 +- crates/editor/src/persistence.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 664882af8e481e..0788d7d51d4c57 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2223,7 +2223,7 @@ impl Editor { .collect(); DB.save_editor_selections(editor_id, workspace_id, selections) .await - .context("persisting editor selections") + .with_context(|| format!("persisting editor selections for editor {editor_id}, workspace {workspace_id:?}")) .log_err(); }); } diff --git a/crates/editor/src/persistence.rs b/crates/editor/src/persistence.rs index e8d2ed05d434b6..d8e9331c4b4ca7 100644 --- a/crates/editor/src/persistence.rs +++ b/crates/editor/src/persistence.rs @@ -247,7 +247,7 @@ impl EditorDb { r#" DELETE FROM editor_selections WHERE editor_id = ?1 AND workspace_id = ?2; -INSERT INTO editor_selections (editor_id, workspace_id, start, end) +INSERT OR IGNORE INTO editor_selections (editor_id, workspace_id, start, end) VALUES {placeholders}; "# );