pgevolve_core/plan/io_error.rs
1//! [`PlanIoError`] — errors raised by plan-directory I/O (read/write).
2
3use std::path::PathBuf;
4
5use thiserror::Error;
6
7use crate::plan::plan::InvalidPlanHash;
8
9/// Errors raised when reading or writing a plan directory
10/// (`plan.sql` + `intent.toml` + `manifest.toml`).
11#[derive(Debug, Error)]
12pub enum PlanIoError {
13 /// I/O error on a specific path.
14 #[error("i/o error on {0}: {1}")]
15 Io(PathBuf, #[source] std::io::Error),
16
17 /// A `-- @pgevolve` directive line failed to parse.
18 #[error("malformed directive: {0}")]
19 MalformedDirective(String),
20
21 /// The plan id encoded in `plan.sql`, `intent.toml`, and `manifest.toml`
22 /// did not agree.
23 #[error("plan id mismatch: sql={sql} intent={intent} manifest={manifest}")]
24 PlanIdMismatch {
25 /// Short plan id parsed from `plan.sql`.
26 sql: String,
27 /// Short plan id parsed from `intent.toml`.
28 intent: String,
29 /// Short plan id parsed from `manifest.toml`.
30 manifest: String,
31 },
32
33 /// TOML parse failure.
34 #[error("toml parse error: {0}")]
35 Toml(#[from] toml::de::Error),
36
37 /// TOML serialize failure (when writing).
38 #[error("toml serialize error: {0}")]
39 TomlSer(#[from] toml::ser::Error),
40
41 /// JSON parse/serialize failure (used by the manifest's embedded
42 /// `target_snapshot_json`).
43 #[error("json error: {0}")]
44 Json(#[from] serde_json::Error),
45
46 /// `manifest.toml`'s `plan_hash` field is not a valid 64-char hex string.
47 #[error(transparent)]
48 InvalidPlanHash(#[from] InvalidPlanHash),
49}
50
51impl PlanIoError {
52 /// Construct an [`PlanIoError::Io`] from a path and an error.
53 pub fn io(path: impl Into<PathBuf>, err: std::io::Error) -> Self {
54 Self::Io(path.into(), err)
55 }
56}