Skip to content

Commit 25e8d54

Browse files
committed
fix: cr
1 parent 5c5c9c4 commit 25e8d54

4 files changed

Lines changed: 34 additions & 31 deletions

File tree

src/common/error/src/status_code.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,34 @@ impl StatusCode {
8686
pub fn is_success(code: u32) -> bool {
8787
Self::Success as u32 == code
8888
}
89+
90+
pub fn is_retryable(&self) -> bool {
91+
match self {
92+
StatusCode::StorageUnavailable
93+
| StatusCode::RuntimeResourcesExhausted
94+
| StatusCode::Internal => true,
95+
96+
StatusCode::Success
97+
| StatusCode::Unknown
98+
| StatusCode::Unsupported
99+
| StatusCode::Unexpected
100+
| StatusCode::InvalidArguments
101+
| StatusCode::InvalidSyntax
102+
| StatusCode::PlanQuery
103+
| StatusCode::EngineExecuteQuery
104+
| StatusCode::TableAlreadyExists
105+
| StatusCode::TableNotFound
106+
| StatusCode::TableColumnNotFound
107+
| StatusCode::TableColumnExists
108+
| StatusCode::DatabaseNotFound
109+
| StatusCode::UserNotFound
110+
| StatusCode::UnsupportedPasswordType
111+
| StatusCode::UserPasswordMismatch
112+
| StatusCode::AuthHeaderNotFound
113+
| StatusCode::InvalidAuthHeader
114+
| StatusCode::AccessDenied => false,
115+
}
116+
}
89117
}
90118

91119
impl fmt::Display for StatusCode {

src/common/procedure/src/error.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -127,38 +127,14 @@ impl Error {
127127
}
128128

129129
/// Determine whether it is a retry later type through [StatusCode]
130-
pub fn is_retry_later(status_code: StatusCode) -> bool {
131-
match status_code {
132-
StatusCode::StorageUnavailable
133-
| StatusCode::RuntimeResourcesExhausted
134-
| StatusCode::Internal => true,
135-
136-
StatusCode::Success
137-
| StatusCode::Unknown
138-
| StatusCode::Unsupported
139-
| StatusCode::Unexpected
140-
| StatusCode::InvalidArguments
141-
| StatusCode::InvalidSyntax
142-
| StatusCode::PlanQuery
143-
| StatusCode::EngineExecuteQuery
144-
| StatusCode::TableAlreadyExists
145-
| StatusCode::TableNotFound
146-
| StatusCode::TableColumnNotFound
147-
| StatusCode::TableColumnExists
148-
| StatusCode::DatabaseNotFound
149-
| StatusCode::UserNotFound
150-
| StatusCode::UnsupportedPasswordType
151-
| StatusCode::UserPasswordMismatch
152-
| StatusCode::AuthHeaderNotFound
153-
| StatusCode::InvalidAuthHeader
154-
| StatusCode::AccessDenied => false,
155-
}
130+
pub fn is_retry_later(&self) -> bool {
131+
matches!(self, Error::RetryLater { .. })
156132
}
157133

158134
/// Creates a new [Error::RetryLater] or [Error::External] error from source `err` according
159135
/// to its [StatusCode].
160136
pub fn from_error_ext<E: ErrorExt + Send + Sync + 'static>(err: E) -> Self {
161-
if Error::is_retry_later(err.status_code()) {
137+
if err.status_code().is_retryable() {
162138
Error::retry_later(err)
163139
} else {
164140
Error::external(err)

src/common/procedure/src/local/runner.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use std::sync::Arc;
1616
use std::time::Duration;
1717

18-
use common_error::ext::ErrorExt;
1918
use common_telemetry::logging;
2019
use tokio::time;
2120

@@ -217,10 +216,10 @@ impl Runner {
217216
"Failed to execute procedure {}-{}, retry: {}",
218217
self.procedure.type_name(),
219218
self.meta.id,
220-
ProcedureError::is_retry_later(e.status_code())
219+
e.is_retry_later(),
221220
);
222221

223-
if ProcedureError::is_retry_later(e.status_code()) {
222+
if e.is_retry_later() {
224223
return ExecResult::RetryLater;
225224
}
226225

src/table-procedure/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ impl ErrorExt for Error {
8484

8585
impl From<Error> for common_procedure::Error {
8686
fn from(e: Error) -> common_procedure::Error {
87-
common_procedure::Error::external(e)
87+
common_procedure::Error::from_error_ext(e)
8888
}
8989
}

0 commit comments

Comments
 (0)