From 9f9e8063fccfaebd5a3c8939c87ef206e0bdca58 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 18 Sep 2025 12:03:35 +0200 Subject: [PATCH] workspace: Pop a toast if manually spawning a task fails (#38405) Release Notes: - N/A *or* Added/Fixed/Improved ... --- crates/workspace/src/tasks.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/workspace/src/tasks.rs b/crates/workspace/src/tasks.rs index 71394c874ae988d7b8fef3e3a224d25e1c290640..5f52cb49e74d67619b9ba7c033a33fe8a7ad51c8 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::(); + w.show_toast(Toast::new(id, format!("Task spawn failed: {e}")), cx); + }) + } None => log::debug!("Task spawn got cancelled"), - } + }; }); self.scheduled_tasks.push(task); }