use std::fmt;
#[derive(Debug, Clone)]
pub struct RpcError {
pub error_type: String,
pub message: String,
pub traceback: String,
pub request_id: String,
}
impl RpcError {
pub fn new(error_type: impl Into<String>, message: impl Into<String>) -> Self {
Self {
error_type: error_type.into(),
message: message.into(),
traceback: String::new(),
request_id: String::new(),
}
}
pub fn value_error(msg: impl Into<String>) -> Self {
Self::new("ValueError", msg)
}
pub fn runtime_error(msg: impl Into<String>) -> Self {
Self::new("RuntimeError", msg)
}
pub fn type_error(msg: impl Into<String>) -> Self {
Self::new("TypeError", msg)
}
pub fn protocol_error(msg: impl Into<String>) -> Self {
Self::new("ProtocolError", msg)
}
pub fn version_error(msg: impl Into<String>) -> Self {
Self::new("VersionError", msg)
}
pub fn permission_error(msg: impl Into<String>) -> Self {
Self::new("PermissionError", msg)
}
pub fn attribute_error(msg: impl Into<String>) -> Self {
Self::new("AttributeError", msg)
}
pub fn session_lost_error(msg: impl Into<String>) -> Self {
Self::new("SessionLostError", msg)
}
pub fn server_draining_error(msg: impl Into<String>) -> Self {
Self::new("ServerDrainingError", msg)
}
}
impl fmt::Display for RpcError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.error_type, self.message)
}
}
impl std::error::Error for RpcError {}
pub type Result<T> = std::result::Result<T, RpcError>;
impl From<arrow_schema::ArrowError> for RpcError {
fn from(e: arrow_schema::ArrowError) -> Self {
RpcError::new("ArrowError", e.to_string())
}
}
impl From<std::io::Error> for RpcError {
fn from(e: std::io::Error) -> Self {
RpcError::new("IOError", e.to_string())
}
}