use std::result::Result as StdResult;
pub type Result<T> = StdResult<T, Error>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("cannot encode {what}: {reason}")]
Encode {
what: String,
reason: String,
},
#[error("cannot decode {what}: {reason}")]
Decode {
what: String,
reason: String,
},
#[error("tiering invariant violated for table {table}: {detail}")]
InvariantViolated {
table: String,
detail: String,
},
#[error("invalid configuration: {0}")]
Config(String),
#[error("table {table} is quarantined: {detail}")]
Quarantined {
table: String,
detail: String,
},
#[error("cannot compare versions across scopes: {left} vs {right}")]
VersionScopeMismatch {
left: String,
right: String,
},
#[error("storage error: {0}")]
Storage(String),
#[error("datafusion error: {0}")]
DataFusion(#[from] datafusion::common::DataFusionError),
#[error("arrow error: {0}")]
Arrow(#[from] crate::arrow::error::ArrowError),
#[error("json error: {0}")]
Json(#[from] serde_json::Error),
}
impl Error {
pub fn encode(what: impl Into<String>, reason: impl Into<String>) -> Self {
Self::Encode {
what: what.into(),
reason: reason.into(),
}
}
pub fn decode(what: impl Into<String>, reason: impl Into<String>) -> Self {
Self::Decode {
what: what.into(),
reason: reason.into(),
}
}
pub fn config(msg: impl Into<String>) -> Self {
Self::Config(msg.into())
}
}
pub(crate) fn redacted(value: &str) -> String {
if value.is_empty() {
return String::new();
}
match value.split_once("://") {
Some((scheme, _)) => format!("{scheme}://<redacted>"),
None => "<redacted>".to_string(),
}
}