[−][src]Macro tari_comms::log_if_error
Log an error if an Err
is returned from the $expr
. If the given expression is Ok(v)
,
Some(v)
is returned, otherwise None
is returned (same as Result::ok
).
Useful in cases where the error should be logged and ignored.
instead of writing if let Err(err) = my_error_call() { error!(...) }
, you can write
log_if_error!(my_error_call())
# use tari_common::log_if_error;
let opt = log_if_error!(target: "docs", level: debug, Result::<(), _>::Err("this will be logged as 'error' tag"), "Error: {error}");
assert_eq!(opt, None);