Skip to content

Commit

Permalink
Don't panic when collaborating with older Zed versions (#7162)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ConradIrwin authored Jan 31, 2024
1 parent 59f77d3 commit 689d430
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 7 additions & 9 deletions crates/editor/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,16 @@ impl FollowableItem for Editor {
.iter()
.map(|excerpt| excerpt.buffer_id)
.collect::<HashSet<_>>();
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::<Result<Vec<_>>>()
})
.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::<Result<Vec<_>>>()
});

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| {
Expand Down
6 changes: 4 additions & 2 deletions crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?)"
))?;
}
}
}
Expand Down

0 comments on commit 689d430

Please sign in to comment.