From 689d43047d5d175596412698430a17df4a06ce0e Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 31 Jan 2024 11:46:03 -0700 Subject: [PATCH] Don't panic when collaborating with older Zed versions (#7162) Older Zed versions may send a buffer id of 0, which is no-longer supported. (as of #6993) This doesn't fix that, but it does ensure that we don't panic in the workspace by maintaining the invariant that from_proto_state returns Some(Task) if the variant matches. It also converts the panic to an error should something similar happen again in the future. Release Notes: - N/A --- crates/editor/src/items.rs | 16 +++++++--------- crates/workspace/src/workspace.rs | 6 ++++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index f26c4361b7e32c681e1d2211bf27a160bac183b8..d9ea6385cb19121c061f6f073988057c989c2d27 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -73,18 +73,16 @@ impl FollowableItem for Editor { .iter() .map(|excerpt| excerpt.buffer_id) .collect::>(); - let buffers = project - .update(cx, |project, cx| { - buffer_ids - .iter() - .map(|id| BufferId::new(*id).map(|id| project.open_buffer_by_id(id, cx))) - .collect::>>() - }) - .ok()?; + let buffers = project.update(cx, |project, cx| { + buffer_ids + .iter() + .map(|id| BufferId::new(*id).map(|id| project.open_buffer_by_id(id, cx))) + .collect::>>() + }); let pane = pane.downgrade(); Some(cx.spawn(|mut cx| async move { - let mut buffers = futures::future::try_join_all(buffers) + let mut buffers = futures::future::try_join_all(buffers?) .await .debug_assert_ok("leaders don't share views for unshared buffers")?; let editor = pane.update(&mut cx, |pane, cx| { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 093393944b06796f699e8d9ef7fbaf579151c51c..177d7384b60f661c3bfd9a6e98ed7f3caa6500f1 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2784,8 +2784,10 @@ impl Workspace { item_tasks.push(task); leader_view_ids.push(id); break; - } else { - assert!(variant.is_some()); + } else if variant.is_none() { + Err(anyhow!( + "failed to construct view from leader (maybe from a different version of zed?)" + ))?; } } }