use std::io;
use thiserror::Error;
use crate::checkpoint::IncompatibleCheckpointDelta;
#[allow(missing_docs)]
#[derive(Debug, Error)]
pub enum MetastoreError {
#[error("Connection error: `{message}`.")]
ConnectionError { message: String },
#[error("Index `{index_id}` already exists.")]
IndexAlreadyExists { index_id: String },
#[error("Access forbidden: `{message}`.")]
Forbidden { message: String },
#[error("Index `{index_id}` does not exist.")]
IndexDoesNotExist { index_id: String },
#[error("Internal error: `{message}` Cause: `{cause}`.")]
InternalError {
message: String,
cause: anyhow::Error,
},
#[error("Failed to deserialize index metadata: `{cause}`")]
InvalidManifest { cause: serde_json::Error },
#[error("IOError `{0}`")]
Io(io::Error),
#[error("Splits `{split_ids:?}` do not exist.")]
SplitsDoNotExist { split_ids: Vec<String> },
#[error("Splits `{split_ids:?}` are not in a deletable state.")]
SplitsNotDeletable { split_ids: Vec<String> },
#[error("Splits `{split_ids:?}` are not staged.")]
SplitsNotStaged { split_ids: Vec<String> },
#[error("Publish checkpoint delta overlaps with the current checkpoint: {0:?}.")]
IncompatibleCheckpointDelta(#[from] IncompatibleCheckpointDelta),
#[error("Source `{source_id}` of type `{source_type}` already exists.")]
SourceAlreadyExists {
source_id: String,
source_type: String,
},
#[error("Source `{source_id}` does not exist.")]
SourceDoesNotExist { source_id: String },
#[cfg(feature = "postgres")]
#[error("Database error: {0:?}.")]
DbError(diesel::result::Error),
}
#[cfg(feature = "postgres")]
impl From<diesel::result::Error> for MetastoreError {
fn from(err: diesel::result::Error) -> MetastoreError {
MetastoreError::DbError(err)
}
}
pub type MetastoreResult<T> = Result<T, MetastoreError>;
#[derive(Error, Debug)]
pub enum MetastoreResolverError {
#[error("Invalid URI format: required: `{0}`")]
InvalidUri(String),
#[error("Unsupported protocol: `{0}`")]
ProtocolUnsupported(String),
#[error("Failed to open metastore: `{0}`")]
FailedToOpenMetastore(MetastoreError),
}