Merge pull request #500 from kdheepak/show-error-spawn-for-task-shortcut

Show error message when spawn fails for task_shortcut
This commit is contained in:
Dheepak Krishnamurthy 2023-05-30 11:47:53 -04:00 committed by GitHub
commit 13f5680c47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 22 deletions

View file

@ -48,7 +48,7 @@ use tui::{
layout::{Alignment, Constraint, Direction, Layout, Margin, Rect}, layout::{Alignment, Constraint, Direction, Layout, Margin, Rect},
style::{Color, Modifier, Style}, style::{Color, Modifier, Style},
terminal::Frame, terminal::Frame,
text::{Span, Line, Text}, text::{Line, Span, Text},
widgets::{Block, BorderType, Borders, Clear, Gauge, LineGauge, List, ListItem, Paragraph, Wrap}, widgets::{Block, BorderType, Borders, Clear, Gauge, LineGauge, List, ListItem, Paragraph, Wrap},
}; };
@ -1887,26 +1887,27 @@ impl TaskwarriorTui {
for i in cmd.iter().skip(1) { for i in cmd.iter().skip(1) {
command.arg(i); command.arg(i);
} }
if let Ok(child) = command.spawn() { match command.spawn() {
let output = child.wait_with_output(); Ok(child) => {
match output { let output = child.wait_with_output();
Ok(o) => { match output {
if o.status.success() { Ok(o) => {
Ok(()) if o.status.success() {
} else { Ok(())
Err(format!( } else {
"Unable to run shortcut {}. Status Code: {} - stdout: {} stderr: {}", Err(format!(
s, "Unable to run shortcut {}. Status Code: {} - stdout: {} stderr: {}",
o.status.code().unwrap_or_default(), s,
String::from_utf8_lossy(&o.stdout), o.status.code().unwrap_or_default(),
String::from_utf8_lossy(&o.stderr), String::from_utf8_lossy(&o.stdout),
)) String::from_utf8_lossy(&o.stderr),
))
}
} }
Err(s) => Err(format!("`{}` failed to wait with output: {}", shell, s)),
} }
Err(s) => Err(format!("`{}` failed to wait with output: {}", shell, s)),
} }
} else { Err(err) => Err(format!("`{}` failed: Unable to spawn shortcut number {} - Error: {}", shell, s, err)),
Err(format!("`{}` failed: Unable to spawn shortcut number {}", shell, s))
} }
} }
None => Err(format!("Unable to run shortcut number {}: shlex::split(`{}`) failed.", s, shell)), None => Err(format!("Unable to run shortcut number {}: shlex::split(`{}`) failed.", s, shell)),

View file

@ -3,7 +3,7 @@ use std::{error::Error, io};
use tui::{ use tui::{
layout::{Constraint, Corner, Direction, Layout}, layout::{Constraint, Corner, Direction, Layout},
style::{Color, Modifier, Style}, style::{Color, Modifier, Style},
text::{Span, Line}, text::{Line, Span},
widgets::{Block, Borders, List, ListItem, ListState}, widgets::{Block, Borders, List, ListItem, ListState},
Terminal, Terminal,
}; };

View file

@ -4,7 +4,7 @@ use tui::{
buffer::Buffer, buffer::Buffer,
layout::{Alignment, Rect}, layout::{Alignment, Rect},
style::{Modifier, Style}, style::{Modifier, Style},
text::{Span, Line, Text}, text::{Line, Span, Text},
widgets::{Block, BorderType, Borders, Clear, Paragraph, Widget}, widgets::{Block, BorderType, Borders, Clear, Paragraph, Widget},
}; };

View file

@ -14,7 +14,7 @@ use tui::{
layout::{Alignment, Rect}, layout::{Alignment, Rect},
style::{Color, Modifier, Style}, style::{Color, Modifier, Style},
symbols, symbols,
text::{Span, Line, Text}, text::{Line, Span, Text},
widgets::{Block, BorderType, Borders, Clear, Paragraph, StatefulWidget, Widget}, widgets::{Block, BorderType, Borders, Clear, Paragraph, StatefulWidget, Widget},
}; };

View file

@ -3,7 +3,7 @@ use tui::{
layout::{Alignment, Constraint, Direction, Layout, Rect}, layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style}, style::{Color, Modifier, Style},
symbols, symbols,
text::{Span, Line}, text::{Line, Span},
widgets::{Block, BorderType, Borders, Cell, LineGauge, Paragraph, Row, Table}, widgets::{Block, BorderType, Borders, Cell, LineGauge, Paragraph, Row, Table},
Frame, Frame,
}; };