This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new c811a300e feat: disable backtrace for NotFound error (#5577)
c811a300e is described below
commit c811a300e137046b27e8b0dce5c7354fdd106405
Author: xxchan <[email protected]>
AuthorDate: Mon Jan 27 14:14:52 2025 +0800
feat: disable backtrace for NotFound error (#5577)
https://github.com/apache/opendal/discussions/5569
Signed-off-by: xxchan <[email protected]>
---
core/src/types/error.rs | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/core/src/types/error.rs b/core/src/types/error.rs
index 4d5514273..01c489bfc 100644
--- a/core/src/types/error.rs
+++ b/core/src/types/error.rs
@@ -93,6 +93,14 @@ impl ErrorKind {
pub fn into_static(self) -> &'static str {
self.into()
}
+
+ /// Capturing a backtrace can be a quite expensive runtime operation.
+ /// For some kinds of errors, backtrace is not useful and we can skip it
(e.g., check if a file exists).
+ ///
+ /// See <https://github.com/apache/opendal/discussions/5569>
+ fn disable_backtrace(&self) -> bool {
+ matches!(self, ErrorKind::NotFound)
+ }
}
impl Display for ErrorKind {
@@ -314,7 +322,11 @@ impl Error {
source: None,
// `Backtrace::capture()` will check if backtrace has been enabled
// internally. It's zero cost if backtrace is disabled.
- backtrace: Backtrace::capture(),
+ backtrace: if kind.disable_backtrace() {
+ Backtrace::disabled()
+ } else {
+ Backtrace::capture()
+ },
}
}