From 1235aa25360081607ccb2795a934a675868ce9ba Mon Sep 17 00:00:00 2001 From: Laurent Mazare Date: Wed, 26 Jul 2023 15:42:46 +0100 Subject: Use bail rather than wrapping a string where possible. (#249) * Use bail rather than wrapping a string where possible. * Revert the cuda default bit. --- candle-core/src/error.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'candle-core/src/error.rs') diff --git a/candle-core/src/error.rs b/candle-core/src/error.rs index 3f860fb0..f9e69122 100644 --- a/candle-core/src/error.rs +++ b/candle-core/src/error.rs @@ -174,6 +174,7 @@ pub enum Error { #[error("unsupported safetensor dtype {0:?}")] UnsupportedSafeTensorDtype(safetensors::Dtype), + /// Arbitrary errors wrapping. #[error(transparent)] Wrapped(Box), @@ -182,6 +183,10 @@ pub enum Error { inner: Box, backtrace: Box, }, + + /// User generated error message, typically created via `bail!`. + #[error("{0}")] + Msg(String), } pub type Result = std::result::Result; @@ -207,12 +212,12 @@ impl Error { #[macro_export] macro_rules! bail { ($msg:literal $(,)?) => { - return Err($crate::Error::Wrapped(format!($msg).into()).bt()) + return Err($crate::Error::Msg(format!($msg).into()).bt()) }; ($err:expr $(,)?) => { - return Err($crate::Error::Wrapped(format!($err).into()).bt()) + return Err($crate::Error::Msg(format!($err).into()).bt()) }; ($fmt:expr, $($arg:tt)*) => { - return Err($crate::Error::Wrapped(format!($fmt, $($arg)*).into()).bt()) + return Err($crate::Error::Msg(format!($fmt, $($arg)*).into()).bt()) }; } -- cgit v1.2.3