1use std::path::PathBuf;
4
5use consortium::dag::DagError;
6
7#[derive(Debug, thiserror::Error)]
9pub enum NixError {
10 #[error("nix evaluation failed for {host}: {message}")]
11 EvalFailed { host: String, message: String },
12
13 #[error("nix build failed for {host}: {message}")]
14 BuildFailed { host: String, message: String },
15
16 #[error("closure copy failed to {host}: {message}")]
17 CopyFailed { host: String, message: String },
18
19 #[error("activation failed on {host}: {message}")]
20 ActivationFailed { host: String, message: String },
21
22 #[error("SSH connection failed to {host}: {message}")]
23 SshFailed { host: String, message: String },
24
25 #[error("builder {host} is unhealthy: {message}")]
26 UnhealthyBuilder { host: String, message: String },
27
28 #[error("no healthy builders available")]
29 NoHealthyBuilders,
30
31 #[error("configuration error: {0}")]
32 Config(#[from] crate::config::ConfigError),
33
34 #[error("IO error: {0}")]
35 Io(#[from] std::io::Error),
36
37 #[error("failed to write machines file to {path}: {source}")]
38 MachinesFile {
39 path: PathBuf,
40 source: std::io::Error,
41 },
42
43 #[error("{0}")]
44 General(String),
45
46 #[error("DAG execution error: {0}")]
47 DagExecution(String),
48}
49
50impl From<DagError> for NixError {
51 fn from(err: DagError) -> Self {
52 NixError::DagExecution(err.to_string())
53 }
54}
55
56impl Clone for NixError {
57 fn clone(&self) -> Self {
58 match self {
59 NixError::EvalFailed { host, message } => NixError::EvalFailed {
60 host: host.clone(),
61 message: message.clone(),
62 },
63 NixError::BuildFailed { host, message } => NixError::BuildFailed {
64 host: host.clone(),
65 message: message.clone(),
66 },
67 NixError::CopyFailed { host, message } => NixError::CopyFailed {
68 host: host.clone(),
69 message: message.clone(),
70 },
71 NixError::ActivationFailed { host, message } => NixError::ActivationFailed {
72 host: host.clone(),
73 message: message.clone(),
74 },
75 NixError::SshFailed { host, message } => NixError::SshFailed {
76 host: host.clone(),
77 message: message.clone(),
78 },
79 NixError::UnhealthyBuilder { host, message } => NixError::UnhealthyBuilder {
80 host: host.clone(),
81 message: message.clone(),
82 },
83 NixError::NoHealthyBuilders => NixError::NoHealthyBuilders,
84 NixError::Config(e) => {
85 NixError::General(format!("config error: {}", e))
87 }
88 NixError::Io(e) => NixError::Io(std::io::Error::new(e.kind(), e.to_string())),
89 NixError::MachinesFile { path, source } => NixError::MachinesFile {
90 path: path.clone(),
91 source: std::io::Error::new(source.kind(), source.to_string()),
92 },
93 NixError::General(msg) => NixError::General(msg.clone()),
94 NixError::DagExecution(msg) => NixError::DagExecution(msg.clone()),
95 }
96 }
97}
98
99pub type Result<T> = std::result::Result<T, NixError>;