From e6d6e1f588db9793e822cdbb1ce2edb2959170c6 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 4 Jun 2022 17:44:26 +0300 Subject: [PATCH] compose: don't unwrap if pseudoterminal creation fails Show error notification instead. --- src/components/mail/compose.rs | 41 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/components/mail/compose.rs b/src/components/mail/compose.rs index d7726406..605231af 100644 --- a/src/components/mail/compose.rs +++ b/src/components/mail/compose.rs @@ -1642,23 +1642,30 @@ impl Component for Composer { ); if *account_settings!(context[self.account_hash].composing.embed) { - self.embed = Some(EmbedStatus::Running( - crate::terminal::embed::create_pty( - width!(self.embed_area), - height!(self.embed_area), - [editor, f.path().display().to_string()].join(" "), - ) - .unwrap(), - f, - )); - self.set_dirty(true); - context - .replies - .push_back(UIEvent::ChangeMode(UIMode::Embed)); - context.replies.push_back(UIEvent::Fork(ForkType::Embed( - self.embed.as_ref().unwrap().lock().unwrap().child_pid, - ))); - self.mode = ViewMode::Embed; + match crate::terminal::embed::create_pty( + width!(self.embed_area), + height!(self.embed_area), + [editor, f.path().display().to_string()].join(" "), + ) { + Ok(embed) => { + self.embed = Some(EmbedStatus::Running(embed, f)); + self.set_dirty(true); + context + .replies + .push_back(UIEvent::ChangeMode(UIMode::Embed)); + context.replies.push_back(UIEvent::Fork(ForkType::Embed( + self.embed.as_ref().unwrap().lock().unwrap().child_pid, + ))); + self.mode = ViewMode::Embed; + } + Err(err) => { + context.replies.push_back(UIEvent::Notification( + Some(format!("Failed to create pseudoterminal: {}", err)), + err.to_string(), + Some(NotificationType::Error(melib::error::ErrorKind::External)), + )); + } + } return true; } /* Kill input thread so that spawned command can be sole receiver of stdin */