fix: error cases

This commit is contained in:
iff 2025-04-05 00:35:08 +02:00
parent e297aa3def
commit e1e9c14b47
2 changed files with 6 additions and 20 deletions

View file

@ -27,14 +27,7 @@ pub fn suggestion(data: &mut Data) {
return; return;
} else { } else {
data.update_command(&data.suggest.clone().unwrap()); data.update_command(&data.suggest.clone().unwrap());
let msg = Some( let msg = Some(execution.err().unwrap());
execution
.err()
.unwrap()
.split_whitespace()
.collect::<Vec<&str>>()
.join(" "),
);
data.update_error(msg); data.update_error(msg);
let retry_message = format!("{}...", t!("retry")); let retry_message = format!("{}...", t!("retry"));
@ -94,14 +87,7 @@ pub fn cnf(data: &mut Data) {
if status.is_err() { if status.is_err() {
let suggest = data.suggest.clone().unwrap(); let suggest = data.suggest.clone().unwrap();
data.update_command(&suggest); data.update_command(&suggest);
let msg = Some( let msg = Some(status.err().unwrap());
status
.err()
.unwrap()
.split_whitespace()
.collect::<Vec<&str>>()
.join(" "),
);
data.update_error(msg); data.update_error(msg);
let retry_message = format!("{}...", t!("retry")); let retry_message = format!("{}...", t!("retry"));
eprintln!("\n{}\n", retry_message.cyan().bold()); eprintln!("\n{}\n", retry_message.cyan().bold());

View file

@ -219,7 +219,7 @@ impl Data {
pub fn update_error(&mut self, error: Option<String>) { pub fn update_error(&mut self, error: Option<String>) {
if let Some(error) = error { if let Some(error) = error {
self.error = error; self.error = error.to_lowercase().split_whitespace().collect::<Vec<&str>>().join(" ");
} else { } else {
self.error = get_error(&self.shell, &self.command); self.error = get_error(&self.shell, &self.command);
} }
@ -271,7 +271,7 @@ pub fn get_error(shell: &str, command: &str) -> String {
} else { } else {
error_output_threaded(shell, command) error_output_threaded(shell, command)
}; };
error.split_whitespace().collect::<Vec<&str>>().join(" ") error.to_lowercase().split_whitespace().collect::<Vec<&str>>().join(" ")
} }
pub fn error_output_threaded(shell: &str, command: &str) -> String { pub fn error_output_threaded(shell: &str, command: &str) -> String {
@ -293,8 +293,8 @@ pub fn error_output_threaded(shell: &str, command: &str) -> String {
match receiver.recv_timeout(Duration::from_secs(3)) { match receiver.recv_timeout(Duration::from_secs(3)) {
Ok(output) => match output.stderr.is_empty() { Ok(output) => match output.stderr.is_empty() {
true => String::from_utf8_lossy(&output.stdout).to_lowercase(), true => String::from_utf8_lossy(&output.stdout).to_string(),
false => String::from_utf8_lossy(&output.stderr).to_lowercase(), false => String::from_utf8_lossy(&output.stderr).to_string(),
}, },
Err(_) => { Err(_) => {
use colored::*; use colored::*;