Skip to content

Commit

Permalink
chore: more specific error on duplicate control id (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
thevaibhav-dixit authored Jan 15, 2025
1 parent 6793442 commit ef61e3b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cala-ledger/src/velocity/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::primitives::*;
#[derive(Error, Debug)]
pub enum VelocityError {
#[error("VelocityError - Sqlx: {0}")]
Sqlx(#[from] sqlx::Error),
Sqlx(sqlx::Error),
#[error("VelocityError - CelError: {0}")]
CelError(#[from] CelError),
#[error("{0}")]
Expand All @@ -21,6 +21,21 @@ pub enum VelocityError {
EsEntityError(es_entity::EsEntityError),
#[error("VelocityError - CursorDestructureError: {0}")]
CursorDestructureError(#[from] es_entity::CursorDestructureError),
#[error("VelocityError - control_id already exists")]
ControlIdAlreadyExists,
}

impl From<sqlx::Error> for VelocityError {
fn from(error: sqlx::Error) -> Self {
if let Some(err) = error.as_database_error() {
if let Some(constraint) = err.constraint() {
if constraint.contains("cala_velocity_controls_pkey") {
return Self::ControlIdAlreadyExists;
}
}
}
Self::Sqlx(error)
}
}

#[derive(Error, Debug)]
Expand Down

0 comments on commit ef61e3b

Please sign in to comment.