Skip to main content

ryra_core/
error.rs

1use std::path::PathBuf;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5    #[error("config not found at {0}")]
6    ConfigNotFound(PathBuf),
7
8    #[error("failed to read {path}: {source}")]
9    FileRead {
10        path: PathBuf,
11        source: std::io::Error,
12    },
13
14    #[error("failed to write {path}: {source}")]
15    FileWrite {
16        path: PathBuf,
17        source: std::io::Error,
18    },
19
20    #[error("failed to parse {path}: {source}")]
21    TomlParse {
22        path: PathBuf,
23        source: toml::de::Error,
24    },
25
26    #[error("failed to serialize config: {0}")]
27    TomlSerialize(#[from] toml::ser::Error),
28
29    #[error(
30        "service {name} not found in any registry{}",
31        crate::registry::format_service_suggestions(suggestions)
32    )]
33    ServiceNotFound {
34        name: String,
35        suggestions: Vec<String>,
36    },
37
38    #[error("service {0} is already installed")]
39    ServiceAlreadyInstalled(String),
40
41    #[error("service {0} is not installed")]
42    ServiceNotInstalled(String),
43
44    #[error(
45        "service {0} has leftover state from a prior install (incomplete install or preserved remove)"
46    )]
47    ServiceIncomplete(String),
48
49    #[error("{service} requires the following services to be installed first: {}", missing.join(", "))]
50    MissingRequiredServices {
51        service: String,
52        missing: Vec<String>,
53    },
54
55    #[error("registry {0} not found")]
56    RegistryNotFound(String),
57
58    #[error("no ports available in range {start}–{end}")]
59    PortsExhausted { start: u16, end: u16 },
60
61    #[error("port {port} is already in use")]
62    PortConflict { port: u16 },
63
64    #[error("git command failed: {0}")]
65    Git(String),
66
67    #[error("systemctl command failed: {0}")]
68    Systemctl(String),
69
70    #[error("directory creation failed for {path}: {source}")]
71    DirCreate {
72        path: PathBuf,
73        source: std::io::Error,
74    },
75
76    #[error("template rendering failed: {0}")]
77    Template(String),
78
79    #[error(
80        "auth integration requires an auth provider to be configured first — run `ryra config auth`"
81    )]
82    AuthNotConfigured,
83
84    #[error("service {0} does not support native OIDC auth")]
85    NoOidcSupport(String),
86
87    #[error("{0}")]
88    UnsupportedArchitecture(String),
89
90    #[error("service '{service}' has no env_group named '{group}'{hint}")]
91    UnknownEnvGroup {
92        service: String,
93        group: String,
94        hint: String,
95    },
96
97    #[error("could not determine home directory: set $HOME")]
98    HomeDirNotFound,
99
100    #[error("invalid service reference: {0}")]
101    InvalidServiceRef(String),
102
103    #[error("registry configuration error: {0}")]
104    RegistryConfig(String),
105
106    #[error("quadlet bundle error: {0}")]
107    Bundle(String),
108
109    #[error("auth context error: {0}")]
110    AuthContext(String),
111
112    #[error("config validation failed: {0}")]
113    ConfigValidation(String),
114
115    #[error(
116        "{service}: {} hand-edited file(s) would be overwritten — re-run with --force to overwrite, or back up your changes first:\n  {}",
117        paths.len(),
118        paths.iter().map(|p| p.display().to_string()).collect::<Vec<_>>().join("\n  ")
119    )]
120    HandEditedFiles {
121        service: String,
122        paths: Vec<PathBuf>,
123    },
124
125    #[error("no backups found for service '{0}' — `ryra upgrade` creates them, run that first")]
126    NoBackup(String),
127
128    #[error(
129        "service '{service}' has no backup at timestamp {stamp} — run `ryra revert {service}` to use the most recent"
130    )]
131    BackupNotFound { service: String, stamp: String },
132
133    #[error(
134        "service '{0}' does not declare backup support — the service author must set `backup = true` under [integrations] in its service.toml first"
135    )]
136    BackupNotSupported(String),
137
138    #[error("backup repository is not configured — run `ryra backup configure` first")]
139    BackupRepoNotConfigured,
140
141    #[error("backup is not enabled for service '{0}' — re-install with `ryra add {0} --backup`")]
142    BackupNotEnabled(String),
143
144    #[error(
145        "no snapshots found for service '{0}' in the backup repository — has `ryra backup run` ever succeeded?"
146    )]
147    BackupNoSnapshots(String),
148
149    #[error("restic command failed: {0}")]
150    Restic(String),
151
152    #[error("backup hook '{hook}' for service '{service}' failed: {message}")]
153    BackupHookFailed {
154        service: String,
155        hook: String,
156        message: String,
157    },
158
159    #[error(
160        "service '{service}' was backed up at manifest hash {backed_up} but current install is at {current} — pass --force to restore anyway, or --migrate-to=<dir> to extract without touching the live install"
161    )]
162    BackupVersionMismatch {
163        service: String,
164        backed_up: String,
165        current: String,
166    },
167}
168
169pub type Result<T> = std::result::Result<T, Error>;