From 1590133d7e8d1f2cc437b683ebeed2f84ff215f7 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sat, 27 Mar 2021 09:39:14 -0600 Subject: do not panic in download --- src/download.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/download.rs b/src/download.rs index 7cf9694..80a159b 100644 --- a/src/download.rs +++ b/src/download.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use anyhow::{Error, Context}; +use anyhow::{bail, Error, Context}; use fehler::throws; use hyper::Uri; use hyper::body::HttpBody; @@ -36,7 +36,7 @@ pub(crate) async fn download(url: Uri, args: &Args) { response = client.get(location).await?; } if !response.status().is_success() { - panic!("non-success response code {} in URL {}", response.status(), url); + bail!("non-success response code {} in URL {}", response.status(), url); } let output_file_path = if let Some(path) = output_file_path { @@ -51,7 +51,7 @@ pub(crate) async fn download(url: Uri, args: &Args) { PathBuf::from(format!("index{}", extension)) }; - let mut output_file = fs::File::create(output_file_path).await.expect("couldn't open output file!"); + let mut output_file = fs::File::create(output_file_path).await?; while let Some(data) = response.body_mut().data().await { output_file.write_all(&data?).await?; -- cgit v1.2.3