mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-28 10:50:39 +00:00
chore: print root cause in opendal logging interceptor (#7183)
* chore: print root cause in opendal Signed-off-by: evenyag <realevenyag@gmail.com> * refactor: extract a function root_source() to get the cause Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com>
This commit is contained in:
@@ -45,3 +45,19 @@ pub fn from_err_code_msg_to_header(code: u32, msg: &str) -> HeaderMap {
|
||||
header.insert(GREPTIME_DB_HEADER_ERROR_MSG, msg);
|
||||
header
|
||||
}
|
||||
|
||||
/// Returns the external root cause of the source error (exclude the current error).
|
||||
pub fn root_source(err: &dyn std::error::Error) -> Option<&dyn std::error::Error> {
|
||||
// There are some divergence about the behavior of the `sources()` API
|
||||
// in https://github.com/rust-lang/rust/issues/58520
|
||||
// So this function iterates the sources manually.
|
||||
let mut root = err.source();
|
||||
while let Some(r) = root {
|
||||
if let Some(s) = r.source() {
|
||||
root = Some(s);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
root
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user