Cleanup messy error messages

This commit is contained in:
topjohnwu
2023-10-12 18:54:09 -07:00
parent b0b04690d5
commit 4b83c1e76c
2 changed files with 36 additions and 19 deletions

View File

@@ -207,6 +207,10 @@ pub trait ResultExt<T> {
fn log_with_msg<F: FnOnce(Formatter) -> fmt::Result>(self, f: F) -> LoggedResult<T>;
}
pub trait ResultNoLog<T> {
fn no_log(self) -> LoggedResult<T>;
}
// Internal C++ bridging logging routines
pub(crate) trait CxxResultExt<T> {
fn log_cxx(self) -> LoggedResult<T>;
@@ -223,6 +227,24 @@ trait LogImpl<T> {
) -> LoggedResult<T>;
}
impl<T, E> ResultNoLog<T> for Result<T, E> {
fn no_log(self) -> LoggedResult<T> {
match self {
Ok(v) => Ok(v),
Err(_) => Err(LoggedError::default()),
}
}
}
impl<T> ResultNoLog<T> for Option<T> {
fn no_log(self) -> LoggedResult<T> {
match self {
Some(v) => Ok(v),
None => Err(LoggedError::default()),
}
}
}
impl<T, R: LogImpl<T>> CxxResultExt<T> for R {
fn log_cxx(self) -> LoggedResult<T> {
self.log_impl(LogLevel::ErrorCxx, None)