type_bridge_migration/error.rs
1//! Error types for migration IR and validation boundaries.
2
3use crate::checksum::ChecksumDrift;
4use crate::graph::MigrationValidationError;
5use thiserror::Error;
6
7/// Crate-local result alias.
8pub type Result<T> = std::result::Result<T, MigrationError>;
9
10/// Migration specification errors.
11#[derive(Debug, Error)]
12pub enum MigrationError {
13 /// JSON serialization or deserialization failed.
14 #[error("invalid migration specification JSON: {0}")]
15 Json(#[from] serde_json::Error),
16 /// Applied migration checksum does not match the loaded migration.
17 #[error("{message}")]
18 ChecksumDrift {
19 /// Structured checksum drift details.
20 drift: Box<ChecksumDrift>,
21 /// Human-readable error message.
22 message: String,
23 },
24 /// Graph validation failed; one or more structural errors were found.
25 #[error("migration graph validation failed with {} error(s)", errors.len())]
26 Planning {
27 /// All validation errors discovered.
28 errors: Vec<MigrationValidationError>,
29 },
30 /// An `OperationSpec` variant is intentionally unsupported by the Rust
31 /// planner.
32 #[error(
33 "operation {kind} is not supported for Rust planning; use RunTypeql or supported typed ops"
34 )]
35 UnloweredOperation {
36 /// Variant name of the unsupported operation.
37 kind: String,
38 },
39 /// The requested target migration was not found in the graph.
40 #[error("target migration not found: {target}")]
41 TargetNotFound {
42 /// The target name that could not be resolved.
43 target: String,
44 },
45 /// The schema generator failed to produce TypeQL from a `DefineSchema` op.
46 #[error("schema generation failed: {message}")]
47 SchemaGeneration {
48 /// Human-readable error message.
49 message: String,
50 },
51 /// An applied-state storage operation failed at the ORM seam.
52 ///
53 /// Carries the ORM-layer failure (connection, transaction, or query
54 /// execution) reworded for the migration error hierarchy. Raised by the
55 /// TypeDB-backed [`MigrationStateStore`](crate::state::MigrationStateStore)
56 /// when a state read or write cannot complete.
57 #[error("migration state storage error: {message}")]
58 State {
59 /// Human-readable error message describing the storage failure.
60 message: String,
61 },
62 /// A sidecar file IO or JSON decode error in the native loader.
63 #[error("migration loader error: {message}")]
64 Loader {
65 /// Human-readable error message describing the loader failure.
66 message: String,
67 },
68 /// A backfill count query or write failed.
69 ///
70 /// Raised by [`backfill::execute_backfill`](crate::backfill::execute_backfill)
71 /// when a count query, the backfill insert, or a transaction open fails.
72 #[error("backfill execution error: {message}")]
73 BackfillQuery {
74 /// Human-readable error message describing the failure.
75 message: String,
76 },
77 /// An executable migration has no checked artifact checksum, so stable
78 /// recovery step identities cannot be constructed.
79 #[error("migration {app_label}.{name} has no checked checksum for recovery execution")]
80 MissingRecoveryChecksum {
81 /// Application or migration package label.
82 app_label: String,
83 /// Migration file stem.
84 name: String,
85 },
86 /// An external per-step recovery controller failed.
87 #[error("migration recovery controller error: {message}")]
88 Recovery {
89 /// Human-readable controller failure.
90 message: String,
91 },
92 /// A detected schema change has no canonical authoring lowering.
93 ///
94 /// The canonical mapper must never silently discard a `SchemaDiff` field
95 /// (#166); a change it cannot express as a typed operation or canonical
96 /// `RunTypeql` is surfaced as this error instead.
97 #[error("unsupported schema change on {type_name}: {change}")]
98 UnsupportedChange {
99 /// The schema type the change applies to.
100 type_name: String,
101 /// Description of the unrepresentable change.
102 change: String,
103 },
104 /// Authoring inputs are inconsistent (e.g. the diff references a type
105 /// that is absent from the schema it was computed from).
106 #[error("inconsistent authoring input: {message}")]
107 AuthoringInput {
108 /// Human-readable error message.
109 message: String,
110 },
111}