Skip to content

Commit

Permalink
Fix panic on executing command directly
Browse files Browse the repository at this point in the history
  • Loading branch information
sachaos committed Oct 4, 2024
1 parent e700171 commit edc422a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use tokio::{
use crate::{
action::Action,
bytes::normalize_stdout,
components::status,
config::{Config, RuntimeConfig},
exec::exec,
store::{Record, Store},
Expand Down Expand Up @@ -39,12 +40,11 @@ pub async fn run_executor<S: Store>(
}

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();
Expand Down Expand Up @@ -113,12 +113,11 @@ pub async fn run_executor_precise<S: Store>(
}

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();
Expand Down
2 changes: 2 additions & 0 deletions src/widget/history_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit edc422a

Please sign in to comment.