Skip to content
Snippets Groups Projects
Commit ccba5cf1 authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon:
Browse files

fix: impl IntoBoxError::error_code for traft::Error

parent 195ae89f
No related branches found
No related tags found
1 merge request!1218return errors from governor to client
......@@ -11,7 +11,6 @@ use crate::traft::error::ErrorInfo;
use crate::traft::node;
use crate::traft::{RaftIndex, RaftTerm};
use std::time::Duration;
use tarantool::error::IntoBoxError;
use tarantool::error::{BoxError, TarantoolErrorCode};
use tarantool::transaction::{transaction, TransactionError};
......
......@@ -103,6 +103,18 @@ impl std::fmt::Display for DisplayIdOfInstance<'_> {
}
impl Error {
pub fn error_code(&self) -> u32 {
match self {
Self::Tarantool(e) => e.error_code(),
Self::NotALeader => ErrorCode::NotALeader as _,
Self::Other { .. } => ErrorCode::Other as _,
Self::NoSuchInstance { .. } => ErrorCode::NoSuchInstance as _,
Self::NoSuchReplicaset { .. } => ErrorCode::NoSuchReplicaset as _,
// TODO: give other error types specific codes
_ => ErrorCode::Other as _,
}
}
#[inline(always)]
pub fn other<E>(error: E) -> Self
where
......@@ -199,21 +211,16 @@ where
}
impl IntoBoxError for Error {
fn error_code(&self) -> u32 {
self.error_code()
}
#[inline]
#[track_caller]
fn into_box_error(self) -> BoxError {
match self {
Self::Tarantool(e) => e.into_box_error(),
Self::NotALeader => BoxError::new(ErrorCode::NotALeader, "not a leader"),
Self::Other(e) => BoxError::new(ErrorCode::Other, e.to_string()),
Self::NoSuchInstance { .. } => {
BoxError::new(ErrorCode::NoSuchInstance, self.to_string())
}
Self::NoSuchReplicaset { .. } => {
BoxError::new(ErrorCode::NoSuchReplicaset, self.to_string())
}
// TODO: give other error types specific codes
other => BoxError::new(ErrorCode::Other, other.to_string()),
_ => BoxError::new(self.error_code(), self.to_string()),
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment