use core::fmt;
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum SeedError {
CyclicForeignKeys { tables: Vec<String> },
MissingParentRows { child: String, parent: String },
UnsafeResetSelection {
parent: String,
skipped_child: String,
},
ParameterLimitTooLow {
table: String,
required: usize,
limit: usize,
},
InvalidValue {
table: String,
column: String,
reason: String,
},
}
impl fmt::Display for SeedError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::CyclicForeignKeys { tables } => write!(
formatter,
"cannot seed a foreign-key cycle in one portable pass: {}",
tables.join(", ")
),
Self::MissingParentRows { child, parent } => write!(
formatter,
"cannot seed {child}: referenced parent {parent} has no generated rows"
),
Self::UnsafeResetSelection {
parent,
skipped_child,
} => write!(
formatter,
"cannot reset {parent} while referenced table {skipped_child} is skipped"
),
Self::ParameterLimitTooLow {
table,
required,
limit,
} => write!(
formatter,
"cannot seed {table}: one row needs {required} bind parameters, above limit {limit}"
),
Self::InvalidValue {
table,
column,
reason,
} => write!(formatter, "cannot seed {table}.{column}: {reason}"),
}
}
}
impl std::error::Error for SeedError {}