From fa7dddd6b56b44711c2cf4100131b735435acbfe Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Fri, 6 Dec 2024 22:11:40 -0500 Subject: [PATCH] gpui: Don't panic when failing to exec system opener (#21674) --- crates/gpui/src/platform/linux/platform.rs | 8 ++++---- crates/gpui/src/platform/mac/platform.rs | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs index d8bdcf1052..d0c0f1768e 100644 --- a/crates/gpui/src/platform/linux/platform.rs +++ b/crates/gpui/src/platform/linux/platform.rs @@ -18,7 +18,7 @@ use std::{ time::Duration, }; -use anyhow::anyhow; +use anyhow::{anyhow, Context as _}; use async_task::Runnable; use calloop::channel::Channel; use calloop::{EventLoop, LoopHandle, LoopSignal}; @@ -382,14 +382,14 @@ impl Platform for P { } fn open_with_system(&self, path: &Path) { - let executor = self.background_executor().clone(); let path = path.to_owned(); - executor + self.background_executor() .spawn(async move { let _ = std::process::Command::new("xdg-open") .arg(path) .spawn() - .expect("Failed to open file with xdg-open"); + .context("invoking xdg-open") + .log_err(); }) .detach(); } diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index f0fe560ca4..096bf860a6 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -10,7 +10,7 @@ use crate::{ PlatformTextSystem, PlatformWindow, Result, ScreenCaptureSource, SemanticVersion, Task, WindowAppearance, WindowParams, }; -use anyhow::anyhow; +use anyhow::{anyhow, Context as _}; use block::ConcreteBlock; use cocoa::{ appkit::{ @@ -57,6 +57,7 @@ use std::{ sync::Arc, }; use strum::IntoEnumIterator; +use util::ResultExt; #[allow(non_upper_case_globals)] const NSUTF8StringEncoding: NSUInteger = 4; @@ -779,15 +780,16 @@ impl Platform for MacPlatform { } fn open_with_system(&self, path: &Path) { - let path = path.to_path_buf(); + let path = path.to_owned(); self.0 .lock() .background_executor .spawn(async move { - std::process::Command::new("open") + let _ = std::process::Command::new("open") .arg(path) .spawn() - .expect("Failed to open file"); + .context("invoking open command") + .log_err(); }) .detach(); }