risingwave_frontend/
error.rsuse risingwave_batch::error::BatchError;
use risingwave_common::array::ArrayError;
use risingwave_common::error::{BoxedError, NoFunction, NotImplemented};
use risingwave_common::secret::SecretError;
use risingwave_common::session_config::SessionConfigError;
use risingwave_common::util::value_encoding::error::ValueEncodingError;
use risingwave_connector::error::ConnectorError;
use risingwave_connector::sink::SinkError;
use risingwave_expr::ExprError;
use risingwave_pb::PbFieldNotFound;
use risingwave_rpc_client::error::{RpcError, TonicStatusWrapper};
use thiserror::Error;
use tokio::task::JoinError;
#[derive(Error, thiserror_ext::ReportDebug, thiserror_ext::Box, thiserror_ext::Macro)]
#[thiserror_ext(newtype(name = RwError, backtrace), macro(path = "crate::error"))]
pub enum ErrorCode {
#[error("internal error: {0}")]
InternalError(String),
#[error(transparent)]
Uncategorized(
#[from]
#[backtrace]
anyhow::Error,
),
#[error("connector error: {0}")]
ConnectorError(
#[source]
#[backtrace]
BoxedError,
),
#[error(transparent)]
NotImplemented(#[from] NotImplemented),
#[error("Not supported: {0}\nHINT: {1}")]
NotSupported(String, String),
#[error(transparent)]
NoFunction(#[from] NoFunction),
#[error(transparent)]
IoError(#[from] std::io::Error),
#[error("Storage error: {0}")]
StorageError(
#[backtrace]
#[source]
BoxedError,
),
#[error("Expr error: {0}")]
ExprError(
#[source]
#[backtrace]
BoxedError,
),
#[error("{0}")]
BatchError(
#[source]
#[backtrace]
BoxedError,
),
#[error("Array error: {0}")]
ArrayError(
#[from]
#[backtrace]
ArrayError,
),
#[error("Stream error: {0}")]
StreamError(
#[backtrace]
#[source]
BoxedError,
),
#[error("{0}")]
RpcError(
#[source]
#[backtrace]
BoxedError,
),
#[error("Bind error: {0}")]
BindError(#[message] String),
#[error("Failed to bind expression: {expr}: {error}")]
BindErrorRoot {
expr: String,
#[source]
#[backtrace]
error: BoxedError,
},
#[error("Catalog error: {0}")]
CatalogError(
#[source]
#[backtrace]
BoxedError,
),
#[error("Protocol error: {0}")]
ProtocolError(String),
#[error("Scheduler error: {0}")]
SchedulerError(
#[source]
#[backtrace]
BoxedError,
),
#[error("Task not found")]
TaskNotFound,
#[error("Session not found")]
SessionNotFound,
#[error("Item not found: {0}")]
ItemNotFound(String),
#[error("Invalid input syntax: {0}")]
InvalidInputSyntax(String),
#[error("Can not compare in memory: {0}")]
MemComparableError(#[from] memcomparable::Error),
#[error("Error while de/se values: {0}")]
ValueEncodingError(
#[from]
#[backtrace]
ValueEncodingError,
),
#[error("Invalid value `{config_value}` for `{config_entry}`")]
InvalidConfigValue {
config_entry: String,
config_value: String,
},
#[error("Invalid Parameter Value: {0}")]
InvalidParameterValue(String),
#[error("Sink error: {0}")]
SinkError(
#[source]
#[backtrace]
BoxedError,
),
#[error("Permission denied: {0}")]
PermissionDenied(String),
#[error("Failed to get/set session config: {0}")]
SessionConfig(
#[from]
#[backtrace]
SessionConfigError,
),
#[error("Secret error: {0}")]
SecretError(
#[from]
#[backtrace]
SecretError,
),
#[error("{0} has been deprecated, please use {1} instead.")]
Deprecated(String, String),
}
pub type Result<T> = std::result::Result<T, RwError>;
impl From<TonicStatusWrapper> for RwError {
fn from(status: TonicStatusWrapper) -> Self {
use tonic::Code;
let message = status.inner().message();
match status.inner().code() {
Code::InvalidArgument => ErrorCode::InvalidParameterValue(message.to_string()),
Code::NotFound | Code::AlreadyExists => ErrorCode::CatalogError(status.into()),
Code::PermissionDenied => ErrorCode::PermissionDenied(message.to_string()),
Code::Cancelled => ErrorCode::SchedulerError(status.into()),
_ => ErrorCode::RpcError(status.into()),
}
.into()
}
}
impl From<RpcError> for RwError {
fn from(r: RpcError) -> Self {
match r {
RpcError::GrpcStatus(status) => TonicStatusWrapper::into(*status),
_ => ErrorCode::RpcError(r.into()).into(),
}
}
}
impl From<ExprError> for RwError {
fn from(s: ExprError) -> Self {
ErrorCode::ExprError(Box::new(s)).into()
}
}
impl From<SinkError> for RwError {
fn from(e: SinkError) -> Self {
ErrorCode::SinkError(Box::new(e)).into()
}
}
impl From<ConnectorError> for RwError {
fn from(e: ConnectorError) -> Self {
ErrorCode::ConnectorError(e.into()).into()
}
}
impl From<PbFieldNotFound> for RwError {
fn from(err: PbFieldNotFound) -> Self {
ErrorCode::InternalError(format!(
"Failed to decode prost: field not found `{}`",
err.0
))
.into()
}
}
impl From<BatchError> for RwError {
fn from(s: BatchError) -> Self {
ErrorCode::BatchError(Box::new(s)).into()
}
}
impl From<JoinError> for RwError {
fn from(join_error: JoinError) -> Self {
ErrorCode::Uncategorized(join_error.into()).into()
}
}
impl From<BoxedError> for RwError {
fn from(e: BoxedError) -> Self {
let e = anyhow::__private::kind::BoxedKind::anyhow_kind(&e).new(e);
ErrorCode::Uncategorized(e).into()
}
}