use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error("while talking to PostgreSQL: {0}")]
Database(#[from] tokio_postgres::Error),
#[error("while acquiring a pooled connection: {0}")]
Pool(#[from] deadpool_postgres::PoolError),
#[error("while building the connection pool: {0}")]
PoolBuild(#[from] deadpool_postgres::BuildError),
#[error("while applying migrations: {0}")]
Migration(#[from] refinery_core::Error),
#[error("while (de)serializing a job payload or carry: {0}")]
Serialization(#[from] serde_json::Error),
#[error("no handler registered for job kind {kind:?}")]
UnknownKind {
kind: String,
},
#[error("invalid configuration: {0}")]
Config(String),
#[error("invalid priority tier {priority}: expected 0 (high), 1 (normal), or 2 (low)")]
InvalidPriority {
priority: i16,
},
#[error("run number {run_no} exceeds the storable range")]
RunNumberOutOfRange {
run_no: u32,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_includes_the_underlying_source() {
let serde_err = serde_json::from_str::<i32>("not a number").unwrap_err();
let source_text = serde_err.to_string();
let shown = Error::from(serde_err).to_string();
assert!(
shown.contains("(de)serializing"),
"keeps the context: {shown}"
);
assert!(
shown.contains(&source_text),
"includes the source detail {source_text:?}: {shown}"
);
}
}