Skip to content

Commit

Permalink
eliminate all unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
fanzeyi committed Aug 16, 2020
1 parent 1d6b79a commit 55eba79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ impl FeedCommand {
}

async fn add(state: State, url: String, group: Option<String>) -> Result<()> {
let bytes = surf::get(&url).await.unwrap().body_bytes().await.unwrap();
let bytes = surf::get(&url)
.await
.map_err(|err| anyhow!("unable to fetch {}: {:?}", &url, err))?
.body_bytes()
.await?;
let channel = rss::Channel::read_from(&bytes[..])?;
let feed = Feed::new(channel.title().to_owned(), url, channel.link().to_owned());
let feed = {
Expand Down Expand Up @@ -242,13 +246,12 @@ impl Options {
.listen(format!("{}:{}", host, port))
.join(crwaler.runloop())
.await;
web.unwrap();
crawl.unwrap();
(web?, crawl?);
Ok(())
}

pub async fn run(self) -> Result<()> {
let pool = crate::model::get_pool(&self.database).unwrap();
let pool = crate::model::get_pool(&self.database)?;
let state = crate::state::State::new(pool);

match self.command {
Expand Down
5 changes: 4 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use thiserror::Error;

macro_rules! error {
($code: expr, $($t:tt)*) => {
::tide::Error::from_str(($code as u16).try_into().unwrap(), format!($($t)*));
::tide::Error::from_str(
($code as u16).try_into().unwrap_or(::tide::StatusCode::BadRequest),
format!($($t)*)
);
};
}

Expand Down

0 comments on commit 55eba79

Please sign in to comment.