cleanup some more expects

This commit is contained in:
Stephan Dilly 2021-05-09 20:39:26 +02:00
parent 423a014b0e
commit 9f37835dc4
3 changed files with 26 additions and 12 deletions

View file

@ -207,6 +207,7 @@ impl FileTreeItems {
for c in &ancestors {
if c.parent().is_some() && !paths_added.contains(c) {
paths_added.insert(c);
//TODO: get rid of expect
let path_string =
String::from(c.to_str().expect("invalid path"));
let is_collapsed = collapsed.contains(&path_string);

View file

@ -11,6 +11,8 @@
#![deny(clippy::needless_update)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::multiple_crate_versions)]
//TODO:
// #![deny(clippy::expect_used)]
mod app;
mod clipboard;
@ -100,7 +102,7 @@ fn main() -> Result<()> {
setup_terminal()?;
defer! {
shutdown_terminal().expect("shutdown failed");
shutdown_terminal();
}
set_panic_handlers()?;
@ -181,10 +183,19 @@ fn setup_terminal() -> Result<()> {
Ok(())
}
fn shutdown_terminal() -> Result<()> {
io::stdout().execute(LeaveAlternateScreen)?;
disable_raw_mode()?;
Ok(())
fn shutdown_terminal() {
let leave_screen =
io::stdout().execute(LeaveAlternateScreen).map(|_f| ());
if let Err(e) = leave_screen {
eprintln!("leave_screen failed:\n{}", e);
}
let leave_raw_mode = disable_raw_mode();
if let Err(e) = leave_raw_mode {
eprintln!("leave_raw_mode failed:\n{}", e);
}
}
fn draw<B: Backend>(
@ -336,19 +347,20 @@ fn set_panic_handlers() -> Result<()> {
// regular panic handler
panic::set_hook(Box::new(|e| {
let backtrace = Backtrace::new();
//TODO: create macro to do both in one
log::error!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
shutdown_terminal().expect("shutdown failed inside panic");
eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
shutdown_terminal();
}));
// global threadpool
rayon_core::ThreadPoolBuilder::new()
.panic_handler(|e| {
let backtrace = Backtrace::new();
//TODO: create macro to do both in one
log::error!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
shutdown_terminal()
.expect("shutdown failed inside panic");
eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
shutdown_terminal();
process::abort();
})
.num_threads(4)

View file

@ -118,7 +118,7 @@ impl DrawableComponent for Status {
self.index.draw(f, left_chunks[1])?;
self.diff.draw(f, chunks[1])?;
self.draw_branch_state(f, &left_chunks);
Self::draw_repo_state(f, left_chunks[0]);
Self::draw_repo_state(f, left_chunks[0])?;
Ok(())
}
@ -213,12 +213,11 @@ impl Status {
fn draw_repo_state<B: tui::backend::Backend>(
f: &mut tui::Frame<B>,
r: tui::layout::Rect,
) {
) -> Result<()> {
if let Ok(state) = asyncgit::sync::repo_state(CWD) {
if state != RepoState::Clean {
let txt = format!("{:?}", state);
let txt_len = u16::try_from(txt.len())
.expect("state name too long");
let txt_len = u16::try_from(txt.len())?;
let w = Paragraph::new(txt)
.style(Style::default().fg(Color::Red))
.alignment(Alignment::Left);
@ -235,6 +234,8 @@ impl Status {
f.render_widget(w, rect);
}
}
Ok(())
}
fn can_focus_diff(&self) -> bool {