From edc422a62b10f0f24e44bee3146be4ca6e440428 Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Fri, 4 Oct 2024 13:52:23 +0900 Subject: [PATCH] Fix panic on executing command directly --- src/runner.rs | 19 +++++++++---------- src/widget/history_item.rs | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/runner.rs b/src/runner.rs index 0ab6922..e59a8fd 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -10,6 +10,7 @@ use tokio::{ use crate::{ action::Action, bytes::normalize_stdout, + components::status, config::{Config, RuntimeConfig}, exec::exec, store::{Record, Store}, @@ -39,12 +40,11 @@ pub async fn run_executor( } let result = exec(runtime_config.command.clone(), shell.clone()).await; - if result.is_err() { - eprintln!("Failed to execute command"); - tokio::time::sleep(runtime_config.interval.to_std().unwrap()).await; - } + let (stdout, stderr, status) = match result { + Ok(result) => result, + Err(e) => (vec![], e.to_string().bytes().collect(), 0), + }; - let (stdout, stderr, status) = result.unwrap(); let exit_code = status; let utf8_stdout = String::from_utf8_lossy(&stdout).to_string(); let utf8_stderr = String::from_utf8_lossy(&stderr).to_string(); @@ -113,12 +113,11 @@ pub async fn run_executor_precise( } let result = exec(runtime_config.command.clone(), shell.clone()).await; - if result.is_err() { - eprintln!("Failed to execute command"); - tokio::time::sleep(runtime_config.interval.to_std().unwrap()).await; - } + let (stdout, stderr, status) = match result { + Ok(result) => result, + Err(e) => (vec![], e.to_string().bytes().collect(), 0), + }; - let (stdout, stderr, status) = result.unwrap(); let exit_code = status; let utf8_stdout = String::from_utf8_lossy(&stdout).to_string(); let utf8_stderr = String::from_utf8_lossy(&stderr).to_string(); diff --git a/src/widget/history_item.rs b/src/widget/history_item.rs index 93765de..9b7c96e 100644 --- a/src/widget/history_item.rs +++ b/src/widget/history_item.rs @@ -92,6 +92,8 @@ impl Widget for HistoryItem { Style::default().fg(Color::Red), ); spans.push(exit_code); + } else if exit_code == 0 { + spans.push(Span::styled(" Err", Style::default().fg(Color::Red))); } else { match self.diff { Some((0, 0)) => spans.push(Span::styled(" ±0", self.secondary_text_style)),