diff --git a/boulder/src/lib.rs b/boulder/src/lib.rs index 67e8e2bcc..4a86bfad3 100644 --- a/boulder/src/lib.rs +++ b/boulder/src/lib.rs @@ -21,3 +21,4 @@ pub mod profile; pub mod recipe; pub mod timing; pub mod upstream; +mod util; diff --git a/boulder/src/package/analysis/handler.rs b/boulder/src/package/analysis/handler.rs index cd163ce86..2efb756bf 100644 --- a/boulder/src/package/analysis/handler.rs +++ b/boulder/src/package/analysis/handler.rs @@ -10,7 +10,7 @@ use std::{ use fs_err::{self as fs, File}; use moss::{Dependency, Provider, dependency}; -use crate::package::collect::PathInfo; +use crate::{package::collect::PathInfo, util::ResultExt as _}; pub use self::elf::elf; pub use self::python::python; @@ -99,8 +99,9 @@ pub fn pkg_config(bucket: &mut BucketMut<'_>, info: &mut PathInfo) -> Result, info: &mut PathInfo) -> Result, info: &mut PathInfo) -> Result { + message: Cow<'static, str>, + error: E, +} + +impl fmt::Display for ErrorWithContext { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(&self.message) + } +} + +impl Error for ErrorWithContext { + fn source(&self) -> Option<&(dyn Error + 'static)> { + Some(&self.error) + } +} + +pub(crate) trait ResultExt { + fn context(self, message: impl Into>) -> Result>; +} + +impl ResultExt for Result { + fn context(self, message: impl Into>) -> Result> { + match self { + Ok(ok) => Ok(ok), + Err(error) => Err(ErrorWithContext { + message: message.into(), + error, + }), + } + } +}