Skip to content

Commit 9f37835

Browse files
author
Stephan Dilly
committed
cleanup some more expects
1 parent 423a014 commit 9f37835

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

Diff for: src/components/utils/filetree.rs

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ impl FileTreeItems {
207207
for c in &ancestors {
208208
if c.parent().is_some() && !paths_added.contains(c) {
209209
paths_added.insert(c);
210+
//TODO: get rid of expect
210211
let path_string =
211212
String::from(c.to_str().expect("invalid path"));
212213
let is_collapsed = collapsed.contains(&path_string);

Diff for: src/main.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#![deny(clippy::needless_update)]
1212
#![allow(clippy::module_name_repetitions)]
1313
#![allow(clippy::multiple_crate_versions)]
14+
//TODO:
15+
// #![deny(clippy::expect_used)]
1416

1517
mod app;
1618
mod clipboard;
@@ -100,7 +102,7 @@ fn main() -> Result<()> {
100102

101103
setup_terminal()?;
102104
defer! {
103-
shutdown_terminal().expect("shutdown failed");
105+
shutdown_terminal();
104106
}
105107

106108
set_panic_handlers()?;
@@ -181,10 +183,19 @@ fn setup_terminal() -> Result<()> {
181183
Ok(())
182184
}
183185

184-
fn shutdown_terminal() -> Result<()> {
185-
io::stdout().execute(LeaveAlternateScreen)?;
186-
disable_raw_mode()?;
187-
Ok(())
186+
fn shutdown_terminal() {
187+
let leave_screen =
188+
io::stdout().execute(LeaveAlternateScreen).map(|_f| ());
189+
190+
if let Err(e) = leave_screen {
191+
eprintln!("leave_screen failed:\n{}", e);
192+
}
193+
194+
let leave_raw_mode = disable_raw_mode();
195+
196+
if let Err(e) = leave_raw_mode {
197+
eprintln!("leave_raw_mode failed:\n{}", e);
198+
}
188199
}
189200

190201
fn draw<B: Backend>(
@@ -336,19 +347,20 @@ fn set_panic_handlers() -> Result<()> {
336347
// regular panic handler
337348
panic::set_hook(Box::new(|e| {
338349
let backtrace = Backtrace::new();
350+
//TODO: create macro to do both in one
339351
log::error!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
340-
shutdown_terminal().expect("shutdown failed inside panic");
341352
eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
353+
shutdown_terminal();
342354
}));
343355

344356
// global threadpool
345357
rayon_core::ThreadPoolBuilder::new()
346358
.panic_handler(|e| {
347359
let backtrace = Backtrace::new();
360+
//TODO: create macro to do both in one
348361
log::error!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
349-
shutdown_terminal()
350-
.expect("shutdown failed inside panic");
351362
eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
363+
shutdown_terminal();
352364
process::abort();
353365
})
354366
.num_threads(4)

Diff for: src/tabs/status.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl DrawableComponent for Status {
118118
self.index.draw(f, left_chunks[1])?;
119119
self.diff.draw(f, chunks[1])?;
120120
self.draw_branch_state(f, &left_chunks);
121-
Self::draw_repo_state(f, left_chunks[0]);
121+
Self::draw_repo_state(f, left_chunks[0])?;
122122

123123
Ok(())
124124
}
@@ -213,12 +213,11 @@ impl Status {
213213
fn draw_repo_state<B: tui::backend::Backend>(
214214
f: &mut tui::Frame<B>,
215215
r: tui::layout::Rect,
216-
) {
216+
) -> Result<()> {
217217
if let Ok(state) = asyncgit::sync::repo_state(CWD) {
218218
if state != RepoState::Clean {
219219
let txt = format!("{:?}", state);
220-
let txt_len = u16::try_from(txt.len())
221-
.expect("state name too long");
220+
let txt_len = u16::try_from(txt.len())?;
222221
let w = Paragraph::new(txt)
223222
.style(Style::default().fg(Color::Red))
224223
.alignment(Alignment::Left);
@@ -235,6 +234,8 @@ impl Status {
235234
f.render_widget(w, rect);
236235
}
237236
}
237+
238+
Ok(())
238239
}
239240

240241
fn can_focus_diff(&self) -> bool {

0 commit comments

Comments
 (0)