Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: disable backtrace for NotFound error #5577

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion core/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
},
}
}

Expand Down
Loading