risingwave_meta/model/
error.rs1use anyhow::anyhow;
16use risingwave_pb::PbFieldNotFound;
17use risingwave_rpc_client::error::ToTonicStatus;
18use thiserror::Error;
19
20pub type MetadataModelResult<T> = std::result::Result<T, MetadataModelError>;
21
22#[derive(Error, Debug)]
23pub enum MetadataModelError {
24 #[error("Pb decode error: {0}")]
25 PbDecode(#[from] prost::DecodeError),
26
27 #[error(transparent)]
28 InternalError(
29 #[from]
30 #[backtrace]
31 anyhow::Error,
32 ),
33}
34
35impl From<PbFieldNotFound> for MetadataModelError {
36 fn from(p: PbFieldNotFound) -> Self {
37 MetadataModelError::InternalError(anyhow::anyhow!(
38 "Failed to decode prost: field not found `{}`",
39 p.0
40 ))
41 }
42}
43
44impl From<MetadataModelError> for tonic::Status {
45 fn from(e: MetadataModelError) -> Self {
46 e.to_status(tonic::Code::Internal, "meta")
47 }
48}
49
50impl MetadataModelError {
51 pub fn internal(msg: impl ToString) -> Self {
52 MetadataModelError::InternalError(anyhow!(msg.to_string()))
53 }
54}