Skip to content

Commit edc422a

Browse files
committed
Fix panic on executing command directly
1 parent e700171 commit edc422a

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/runner.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use tokio::{
1010
use crate::{
1111
action::Action,
1212
bytes::normalize_stdout,
13+
components::status,
1314
config::{Config, RuntimeConfig},
1415
exec::exec,
1516
store::{Record, Store},
@@ -39,12 +40,11 @@ pub async fn run_executor<S: Store>(
3940
}
4041

4142
let result = exec(runtime_config.command.clone(), shell.clone()).await;
42-
if result.is_err() {
43-
eprintln!("Failed to execute command");
44-
tokio::time::sleep(runtime_config.interval.to_std().unwrap()).await;
45-
}
43+
let (stdout, stderr, status) = match result {
44+
Ok(result) => result,
45+
Err(e) => (vec![], e.to_string().bytes().collect(), 0),
46+
};
4647

47-
let (stdout, stderr, status) = result.unwrap();
4848
let exit_code = status;
4949
let utf8_stdout = String::from_utf8_lossy(&stdout).to_string();
5050
let utf8_stderr = String::from_utf8_lossy(&stderr).to_string();
@@ -113,12 +113,11 @@ pub async fn run_executor_precise<S: Store>(
113113
}
114114

115115
let result = exec(runtime_config.command.clone(), shell.clone()).await;
116-
if result.is_err() {
117-
eprintln!("Failed to execute command");
118-
tokio::time::sleep(runtime_config.interval.to_std().unwrap()).await;
119-
}
116+
let (stdout, stderr, status) = match result {
117+
Ok(result) => result,
118+
Err(e) => (vec![], e.to_string().bytes().collect(), 0),
119+
};
120120

121-
let (stdout, stderr, status) = result.unwrap();
122121
let exit_code = status;
123122
let utf8_stdout = String::from_utf8_lossy(&stdout).to_string();
124123
let utf8_stderr = String::from_utf8_lossy(&stderr).to_string();

src/widget/history_item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ impl Widget for HistoryItem {
9292
Style::default().fg(Color::Red),
9393
);
9494
spans.push(exit_code);
95+
} else if exit_code == 0 {
96+
spans.push(Span::styled(" Err", Style::default().fg(Color::Red)));
9597
} else {
9698
match self.diff {
9799
Some((0, 0)) => spans.push(Span::styled(" ±0", self.secondary_text_style)),

0 commit comments

Comments
 (0)