Skip to content

Commit 628405d

Browse files
committed
feat: created version of blame_err! that doesn't return
This is just a nice to have that's quite helpful.
1 parent 85d7f4a commit 628405d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/perseus/src/errors.rs

+32
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,35 @@ macro_rules! blame_err {
319319
})
320320
};
321321
}
322+
323+
/// This macro is identical to [`blame_err!`], except it will simply return a
324+
/// [`GenericErrorWithCause`], not `return`ing it from the caller function. This
325+
/// is more useful if you're providing a blamed error to something like
326+
/// `.map_err()`.
327+
#[macro_export]
328+
macro_rules! make_blamed_err {
329+
(client, $err:expr) => {
330+
::perseus::GenericErrorWithCause {
331+
error: $err.into(),
332+
cause: $crate::ErrorCause::Client(::std::option::Option::None),
333+
}
334+
};
335+
(client, $code:literal, $err:expr) => {
336+
::perseus::GenericErrorWithCause {
337+
error: $err.into(),
338+
cause: $crate::ErrorCause::Client(::std::option::Option::Some($code)),
339+
}
340+
};
341+
(server, $err:expr) => {
342+
::perseus::GenericErrorWithCause {
343+
error: $err.into(),
344+
cause: $crate::ErrorCause::Server(::std::option::Option::None),
345+
}
346+
};
347+
(server, $code:literal, $err:expr) => {
348+
::perseus::GenericErrorWithCause {
349+
error: $err.into(),
350+
cause: $crate::ErrorCause::Server(::std::option::Option::Some($code)),
351+
}
352+
};
353+
}

0 commit comments

Comments
 (0)