Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
workspace: Pop a toast if manually spawning a task fails (#38405)
Lukas Wirth9f9e8063fccf
diff --git a/crates/workspace/src/tasks.rs b/crates/workspace/src/tasks.rsindex 71394c874ae..5f52cb49e74 100644--- a/crates/workspace/src/tasks.rs+++ b/crates/workspace/src/tasks.rs@@ -8,7 +8,7 @@ use remote::ConnectionState;use task::{DebugScenario, ResolvedTask, SpawnInTerminal, TaskContext, TaskTemplate};use ui::Window;-use crate::Workspace;+use crate::{Toast, Workspace, notifications::NotificationId};impl Workspace {pub fn schedule_task(@@ -73,8 +73,10 @@ impl Workspace {if let Some(terminal_provider) = self.terminal_provider.as_ref() {let task_status = terminal_provider.spawn(spawn_in_terminal, window, cx);- let task = cx.background_spawn(async move {- match task_status.await {++ let task = cx.spawn(async |w, cx| {+ let res = cx.background_spawn(task_status).await;+ match res {Some(Ok(status)) => {if status.success() {log::debug!("Task spawn succeeded");@@ -82,9 +84,15 @@ impl Workspace {log::debug!("Task spawn failed, code: {:?}", status.code());}}- Some(Err(e)) => log::error!("Task spawn failed: {e:#}"),+ Some(Err(e)) => {+ log::error!("Task spawn failed: {e:#}");+ _ = w.update(cx, |w, cx| {+ let id = NotificationId::unique::<ResolvedTask>();+ w.show_toast(Toast::new(id, format!("Task spawn failed: {e}")), cx);+ })+ }None => log::debug!("Task spawn got cancelled"),- }+ };});self.scheduled_tasks.push(task);}