1use coil_config::DatabaseDriver;
2use thiserror::Error;
3
4use crate::{FilterOperator, MutationAction};
5
6#[derive(Debug, Error, Clone, PartialEq, Eq)]
7pub enum DataModelError {
8 #[error("`{field}` cannot be empty")]
9 EmptyField { field: &'static str },
10 #[error("`{field}` contains an invalid token `{value}`")]
11 InvalidToken { field: &'static str, value: String },
12 #[error("page size must be greater than zero")]
13 InvalidPageSize,
14 #[error("database pool sizing is invalid: min={min_connections} max={max_connections}")]
15 InvalidPoolSizing {
16 min_connections: u16,
17 max_connections: u16,
18 },
19 #[error("statement timeout must be greater than zero")]
20 InvalidStatementTimeout,
21 #[error("migration `{migration_id}` is duplicated for owner `{owner}`")]
22 DuplicateMigration { owner: String, migration_id: String },
23 #[error("repository `{repository}` must declare at least one projected field")]
24 EmptyProjection { repository: String },
25 #[error("field `{field}` is not declared on repository `{repository}`")]
26 UnknownRepositoryField { repository: String, field: String },
27 #[error("filter operator `{operator}` expected {expected} value(s) but received {actual}")]
28 InvalidFilterArity {
29 operator: FilterOperator,
30 expected: &'static str,
31 actual: usize,
32 },
33 #[error("transaction plan expected {expected} writes but received {actual} mutations")]
34 TransactionWriteCountMismatch { expected: usize, actual: usize },
35 #[error("mutation `{action}` on table `{table}` must declare at least one assignment")]
36 MissingMutationAssignments {
37 table: String,
38 action: MutationAction,
39 },
40 #[error("mutation `{action}` on table `{table}` must declare at least one predicate")]
41 MissingMutationPredicates {
42 table: String,
43 action: MutationAction,
44 },
45 #[error("upsert on table `{table}` must declare at least one conflict field")]
46 MissingConflictFields { table: String },
47 #[error("database connection secret is not configured")]
48 MissingConnectionSecret,
49 #[error("environment variable `{var}` is not set for the database connection secret")]
50 MissingConnectionSecretEnv { var: String },
51 #[error("secret reference `{secret_ref}` is not supported by the local data runtime")]
52 UnsupportedSecretRef { secret_ref: String },
53 #[error("database driver `{driver:?}` does not support sqlx-backed postgres execution")]
54 UnsupportedSqlxDriver { driver: DatabaseDriver },
55 #[error("database connection URL is invalid: {reason}")]
56 InvalidConnectionUrl { reason: String },
57 #[error("unsigned value `{value}` cannot be represented as a Postgres BIGINT bind")]
58 UnsupportedUnsignedBindValue { value: u64 },
59 #[error("sqlx execution failed: {reason}")]
60 Sqlx { reason: String },
61 #[error("migration `{migration_id}` has no SQL statements to apply")]
62 MissingMigrationStatements { migration_id: String },
63}