1use thiserror::Error;
9
10#[derive(Error, Debug)]
12pub enum SeedKitError {
13 #[error("Database connection failed: {message}\n Connection string: {connection_hint}\n Cause: {source}")]
14 Connection {
15 message: String,
16 connection_hint: String,
17 #[source]
18 source: sqlx::Error,
19 },
20
21 #[error("Schema introspection failed on query '{query}': {source}")]
22 Introspection {
23 query: String,
24 #[source]
25 source: sqlx::Error,
26 },
27
28 #[error("No database URL provided. SeedKit looks for a connection in this order:\n 1. --db flag\n 2. DATABASE_URL environment variable\n 3. .env file with DATABASE_URL\n 4. seedkit.toml [database] section\n\nExample: seedkit generate --db postgres://localhost/myapp --rows 100")]
29 NoDatabaseUrl,
30
31 #[error("Unsupported database scheme '{scheme}'. Supported: postgres://, mysql://, sqlite://")]
32 UnsupportedDatabase { scheme: String },
33
34 #[error("Circular dependency detected involving tables: {tables}\n SeedKit will attempt to break cycles using nullable FK columns.\n You can override this in seedkit.toml:\n [graph]\n break_cycle_at = [\"{suggested_break}\"]")]
35 CircularDependency {
36 tables: String,
37 suggested_break: String,
38 },
39
40 #[error("No breakable edge found for circular dependency involving: {tables}\n All FK columns in the cycle are NOT NULL. Consider:\n 1. Making one FK column nullable\n 2. Adding a break_cycle_at override in seedkit.toml")]
41 UnbreakableCycle { tables: String },
42
43 #[error("Failed to generate unique value for {table}.{column} at row {row_index}: {max_retries} retries exhausted\n Consider reducing --rows or adding more variation to the column's generator")]
44 UniqueExhausted {
45 table: String,
46 column: String,
47 row_index: usize,
48 max_retries: usize,
49 },
50
51 #[error("Insert failed on {table} row {row_index}: {message}\n SQL: {sql_preview}\n DB error: {source}")]
52 InsertFailed {
53 table: String,
54 row_index: usize,
55 message: String,
56 sql_preview: String,
57 #[source]
58 source: sqlx::Error,
59 },
60
61 #[error("Cannot apply deferred update to {table} row {row_index}: {message}")]
62 DeferredUpdateTarget {
63 table: String,
64 row_index: usize,
65 message: String,
66 },
67
68 #[error("Foreign key resolution failed: {source_table}.{source_column} references {target_table}.{target_column}, but target table has no generated rows")]
69 ForeignKeyResolution {
70 source_table: String,
71 source_column: String,
72 target_table: String,
73 target_column: String,
74 },
75
76 #[error("Lock file error: {message}")]
77 LockFile { message: String },
78
79 #[error("Schema drift detected: {message}")]
80 SchemaDrift { message: String },
81
82 #[error("Configuration error: {message}")]
83 Config { message: String },
84
85 #[error("LLM API error: {message}")]
86 LlmError { message: String },
87
88 #[error("Output error: {message}: {source}")]
89 Output {
90 message: String,
91 #[source]
92 source: std::io::Error,
93 },
94
95 #[error("Check constraint cannot be satisfied for {table}.{column}: {constraint}\n Generated value {value} violates the constraint")]
96 CheckConstraintViolation {
97 table: String,
98 column: String,
99 constraint: String,
100 value: String,
101 },
102
103 #[error("Composite unique constraint exhausted on {table}.({columns}) at row {row_index}: {max_retries} retries exhausted\n The combination of values for these columns could not be made unique")]
104 CompositeUniqueExhausted {
105 table: String,
106 columns: String,
107 row_index: usize,
108 max_retries: usize,
109 },
110
111 #[error("{0}")]
112 Other(String),
113}
114
115pub type Result<T> = std::result::Result<T, SeedKitError>;