Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
persistence: More error contexts (#40787)
Lukas Wirth0be70e24d66a
diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rsindex 708efbbe979..f8e8f1c3750 100644--- a/crates/editor/src/items.rs+++ b/crates/editor/src/items.rs@@ -1079,12 +1079,17 @@ impl SerializableItem for Editor {}}Ok(None) => {- return Task::ready(Err(anyhow!("No path or contents found for buffer")));+ return Task::ready(Err(anyhow!(+ "Unable to deserialize editor: No entry in database for item_id: {item_id} and workspace_id {workspace_id:?}"+ )));}Err(error) => {return Task::ready(Err(error));}};+ log::debug!(+ "Deserialized editor {item_id:?} in workspace {workspace_id:?}, {serialized_editor:?}"+ );match serialized_editor {SerializedEditor {@@ -1112,7 +1117,8 @@ impl SerializableItem for Editor {// First create the empty bufferlet buffer = project.update(cx, |project, cx| project.create_buffer(true, cx))?- .await?;+ .await+ .context("Failed to create buffer while deserializing editor")?;// Then set the text so that the dirty bit is set correctlybuffer.update(cx, |buffer, cx| {@@ -1154,7 +1160,9 @@ impl SerializableItem for Editor {match opened_buffer {Some(opened_buffer) => {window.spawn(cx, async move |cx| {- let (_, buffer) = opened_buffer.await?;+ let (_, buffer) = opened_buffer+ .await+ .context("Failed to open path in project")?;// This is a bit wasteful: we're loading the whole buffer from// disk and then overwrite the content.@@ -1220,7 +1228,8 @@ impl SerializableItem for Editor {} => window.spawn(cx, async move |cx| {let buffer = project.update(cx, |project, cx| project.create_buffer(true, cx))?- .await?;+ .await+ .context("Failed to create buffer")?;cx.update(|window, cx| {cx.new(|cx| {diff --git a/crates/project/src/buffer_store.rs b/crates/project/src/buffer_store.rsindex b36b44cfd4d..51bca611f4b 100644--- a/crates/project/src/buffer_store.rs+++ b/crates/project/src/buffer_store.rs@@ -24,7 +24,7 @@ use rpc::{use std::{io, sync::Arc, time::Instant};use text::{BufferId, ReplicaId};-use util::{ResultExt as _, TryFutureExt, debug_panic, maybe, rel_path::RelPath};+use util::{ResultExt as _, TryFutureExt, debug_panic, maybe, paths::PathStyle, rel_path::RelPath};use worktree::{File, PathChange, ProjectEntryId, Worktree, WorktreeId};/// A set of open buffers.@@ -621,8 +621,11 @@ impl LocalBufferStore {let load_file = worktree.load_file(path.as_ref(), cx);let reservation = cx.reserve_entity();let buffer_id = BufferId::from(reservation.entity_id().as_non_zero_u64());+ let path = path.clone();cx.spawn(async move |_, cx| {- let loaded = load_file.await?;+ let loaded = load_file.await.with_context(|| {+ format!("Could not open path: {}", path.display(PathStyle::local()))+ })?;let text_buffer = cx.background_spawn(async move {text::Buffer::new(ReplicaId::LOCAL, buffer_id, loaded.text)diff --git a/crates/workspace/src/persistence/model.rs b/crates/workspace/src/persistence/model.rsindex 08a2f2e38dd..a37b2ebbe93 100644--- a/crates/workspace/src/persistence/model.rs+++ b/crates/workspace/src/persistence/model.rs@@ -3,7 +3,7 @@ use crate::{Member, Pane, PaneAxis, SerializableItemRegistry, Workspace, WorkspaceId, item::ItemHandle,path_list::PathList,};-use anyhow::Result;+use anyhow::{Context, Result};use async_recursion::async_recursion;use collections::IndexSet;use db::sqlez::{@@ -220,6 +220,7 @@ impl SerializedPaneGroup {let new_items = serialized_pane.deserialize_to(project, &pane, workspace_id, workspace.clone(), cx).await+ .context("Could not deserialize pane)").log_err()?;if panediff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rsindex f889fb3b821..5f8253e2dfb 100644--- a/crates/worktree/src/worktree.rs+++ b/crates/worktree/src/worktree.rs@@ -1706,9 +1706,9 @@ impl LocalWorktree {refresh.recv().await;log::trace!("refreshed entry {path:?} in {:?}", t0.elapsed());let new_entry = this.read_with(cx, |this, _| {- this.entry_for_path(&path)- .cloned()- .context("reading path after update")+ this.entry_for_path(&path).cloned().with_context(|| {+ format!("Could not find entry in worktree for {path:?} after refresh")+ })})??;Ok(Some(new_entry))})