Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: more specific error on duplicate control id #295

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading