Skip to content

Commit

Permalink
use anyhow::bail
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed Oct 25, 2020
1 parent 3b44ac5 commit 0f5b8a0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
tabs::{Revlog, StashList, Stashing, Status},
ui::style::{SharedTheme, Theme},
};
use anyhow::{anyhow, Result};
use anyhow::{bail, Result};
use asyncgit::{sync, AsyncNotification, CWD};
use crossbeam_channel::Sender;
use crossterm::event::{Event, KeyEvent};
Expand Down Expand Up @@ -199,7 +199,7 @@ impl App {
1 => self.revlog.draw(f, chunks_main[1])?,
2 => self.stashing_tab.draw(f, chunks_main[1])?,
3 => self.stashlist_tab.draw(f, chunks_main[1])?,
_ => return Err(anyhow!("unknown tab")),
_ => bail!("unknown tab"),
};

self.draw_popups(f)?;
Expand Down
4 changes: 2 additions & 2 deletions src/components/externaleditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
strings,
ui::{self, style::SharedTheme},
};
use anyhow::{anyhow, Result};
use anyhow::{anyhow, bail, Result};
use asyncgit::{sync::utils::repo_work_dir, CWD};
use crossterm::{
event::Event,
Expand Down Expand Up @@ -56,7 +56,7 @@ impl ExternalEditorComponent {
};

if !path.exists() {
return Err(anyhow!("file not found: {:?}", path));
bail!("file not found: {:?}", path);
}

io::stdout().execute(LeaveAlternateScreen)?;
Expand Down
11 changes: 3 additions & 8 deletions src/components/utils/filetree.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{bail, Result};
use asyncgit::StatusItem;
use std::{
collections::BTreeSet,
Expand Down Expand Up @@ -75,9 +75,7 @@ impl FileTreeItem {
),
kind: FileTreeItemKind::File(item.clone()),
}),
None => {
Err(anyhow::anyhow!("invalid file name {:?}", item))
}
None => bail!("invalid file name {:?}", item),
}
}

Expand All @@ -102,10 +100,7 @@ impl FileTreeItem {
collapsed,
)),
}),

None => Err(anyhow::anyhow!(
"failed to create item from path"
)),
None => bail!("failed to create item from path"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod ui;
mod version;

use crate::app::App;
use anyhow::{anyhow, Result};
use anyhow::{anyhow, bail, Result};
use asyncgit::AsyncNotification;
use backtrace::Backtrace;
use clap::{
Expand Down Expand Up @@ -213,7 +213,7 @@ fn select_event(
1 => oper.recv(rx_git).map(QueueEvent::GitEvent),
2 => oper.recv(rx_ticker).map(|_| QueueEvent::Tick),
3 => oper.recv(rx_spinner).map(|_| QueueEvent::SpinnerUpdate),
_ => return Err(anyhow!("unknown select source")),
_ => bail!("unknown select source"),
}?;

Ok(ev)
Expand Down

0 comments on commit 0f5b8a0

Please sign in to comment.