use anyhow::bail

This commit is contained in:
Stephan Dilly 2020-10-25 23:57:26 +01:00
parent 3b44ac5b06
commit 0f5b8a0909
4 changed files with 9 additions and 14 deletions

View file

@ -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};
@ -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)?;

View file

@ -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,
@ -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)?;

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{bail, Result};
use asyncgit::StatusItem;
use std::{
collections::BTreeSet,
@ -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),
}
}
@ -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"),
}
}
}

View file

@ -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::{
@ -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)