-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rsjudge-utils): ✨ add generic error logging support
- Loading branch information
1 parent
7ff8399
commit 27c6d80
Showing
8 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ rust-version.workspace = true | |
|
||
[dependencies] | ||
anyhow = "1.0.81" | ||
log.workspace = true | ||
shell-words = "1.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! Macro for logging when error occurs. | ||
/// Log an error message and return an `Err` variant of `Result`. | ||
/// | ||
/// This macro is transparent and does not affect the return value. | ||
/// You may still want to use `?` to propagate the error to the caller. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use anyhow::{anyhow, Result}; | ||
/// use rsjudge_utils::log_if_error; | ||
/// | ||
/// let result: Result<()> = Err(anyhow!("An error")); | ||
/// log_if_error!(result); | ||
/// ``` | ||
#[macro_export] | ||
macro_rules! log_if_error { | ||
($expr: expr) => { | ||
$expr.map_err(|err| { | ||
::log::error!("{}", err); | ||
err | ||
}) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters