diff --git a/src/archive.rs b/src/archive.rs index 676a66d..435e700 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -4,7 +4,7 @@ //! Tools for creating and inserting into tarballs. -use anyhow::{anyhow, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use async_trait::async_trait; use camino::Utf8Path; use flate2::write::GzEncoder; @@ -106,10 +106,10 @@ pub async fn add_package_to_zone_archive( let tmp = camino_tempfile::tempdir()?; let gzr = flate2::read::GzDecoder::new(open_tarfile(package_path)?); if gzr.header().is_none() { - return Err(anyhow!( + bail!( "Missing gzip header from {} - cannot add it to zone image", package_path, - )); + ); } let mut component_reader = tar::Archive::new(gzr); let entries = component_reader.entries()?; diff --git a/src/package.rs b/src/package.rs index adde5bb..c148076 100644 --- a/src/package.rs +++ b/src/package.rs @@ -52,7 +52,7 @@ fn zone_get_all_parent_inputs(to: &Utf8Path) -> Result> { parents.reverse(); if to.is_relative() { - return Err(anyhow!("Cannot add 'to = {to}'; absolute path required",)); + bail!("Cannot add 'to = {to}'; absolute path required"); } let mut outputs = vec![]; @@ -452,11 +452,11 @@ impl Package { if !from.exists() { // Strictly speaking, this check is redundant, but it provides // a better error message. - return Err(anyhow!( + bail!( "Cannot add path \"{}\" to package \"{}\" because it does not exist", from, self.service_name, - )); + ); } let from_root = std::fs::canonicalize(&from) @@ -543,10 +543,10 @@ impl Package { } } _ => { - return Err(anyhow!( + bail!( "Cannot walk over a zone package with source: {:?}", self.source - )); + ); } }