This is an automated email from the ASF dual-hosted git repository. tison 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 b2e00f4b9 feat: expose APIs for ErrorStatus (#6513) b2e00f4b9 is described below commit b2e00f4b943dea8e008434d6e120f3fdded46f26 Author: tison <wander4...@gmail.com> AuthorDate: Tue Aug 19 15:17:56 2025 +0800 feat: expose APIs for ErrorStatus (#6513) Signed-off-by: tison <wander4...@gmail.com> --- core/src/types/error.rs | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/core/src/types/error.rs b/core/src/types/error.rs index 141a805a9..28c52a273 100644 --- a/core/src/types/error.rs +++ b/core/src/types/error.rs @@ -134,7 +134,7 @@ enum ErrorStatus { /// /// For example, underlying services returns a not found error. /// - /// Users SHOULD never retry this operation. + /// Users MUST never retry this operation. Permanent, /// Temporary means this error is returned for temporary. /// @@ -146,7 +146,7 @@ enum ErrorStatus { /// /// For example, underlying services kept returning network errors. /// - /// Users MAY retry this operation but it's highly possible to error again. + /// Users SHOULD NOT retry this operation, since it's highly possible to error again. Persistent, } @@ -377,6 +377,8 @@ impl Error { } /// Set permanent status for error. + /// + /// By set permanent, we indicate the retry must be stopped. pub fn set_permanent(mut self) -> Self { self.status = ErrorStatus::Permanent; self @@ -390,21 +392,41 @@ impl Error { self } + /// Set persistent status for error. + /// + /// By setting persistent, we indicate the retry should be stopped. + pub fn set_persistent(mut self) -> Self { + self.status = ErrorStatus::Persistent; + self + } + + /// Set permanent status for error by given permanent. + /// + /// By set permanent, we indicate the retry must be stopped. + pub fn with_permanent(mut self, permanent: bool) -> Self { + if permanent { + self.status = ErrorStatus::Permanent; + } + self + } + /// Set temporary status for error by given temporary. /// /// By set temporary, we indicate this error is retryable. - pub(crate) fn with_temporary(mut self, temporary: bool) -> Self { + pub fn with_temporary(mut self, temporary: bool) -> Self { if temporary { self.status = ErrorStatus::Temporary; } self } - /// Set persistent status for error. + /// Set persistent status for error by given persistent. /// - /// By setting persistent, we indicate the retry should be stopped. - pub fn set_persistent(mut self) -> Self { - self.status = ErrorStatus::Persistent; + /// By set persistent, we indicate the retry should be stopped. + pub fn with_persistent(mut self, persistent: bool) -> Self { + if persistent { + self.status = ErrorStatus::Persistent; + } self } @@ -413,11 +435,21 @@ impl Error { self.kind } + /// Check if this error is permanent. + pub fn is_permanent(&self) -> bool { + self.status == ErrorStatus::Permanent + } + /// Check if this error is temporary. pub fn is_temporary(&self) -> bool { self.status == ErrorStatus::Temporary } + /// Check if this error is persistent. + pub fn is_persistent(&self) -> bool { + self.status == ErrorStatus::Persistent + } + /// Return error's backtrace. /// /// Note: the standard way of exposing backtrace is the unstable feature [`error_generic_member_access`](https://github.com/rust-lang/rust/issues/99301).