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 add authelia`"
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("`ryra configure` can't change {field} for service '{service}'. {workaround}")]
98    ConfigureUnsupported {
99        service: String,
100        field: String,
101        workaround: String,
102    },
103
104    #[error("could not determine home directory: set $HOME")]
105    HomeDirNotFound,
106
107    #[error("invalid service reference: {0}")]
108    InvalidServiceRef(String),
109
110    #[error("registry configuration error: {0}")]
111    RegistryConfig(String),
112
113    #[error("quadlet bundle error: {0}")]
114    Bundle(String),
115
116    #[error("auth context error: {0}")]
117    AuthContext(String),
118
119    #[error("config validation failed: {0}")]
120    ConfigValidation(String),
121
122    #[error(
123        "{service}: {} hand-edited file(s) would be overwritten — re-run with --force to overwrite, or back up your changes first:\n  {}",
124        paths.len(),
125        paths.iter().map(|p| p.display().to_string()).collect::<Vec<_>>().join("\n  ")
126    )]
127    HandEditedFiles {
128        service: String,
129        paths: Vec<PathBuf>,
130    },
131
132    #[error("no backups found for service '{0}' — `ryra upgrade` creates them, run that first")]
133    NoBackup(String),
134
135    #[error(
136        "service '{service}' has no backup at timestamp {stamp} — run `ryra revert {service}` to use the most recent"
137    )]
138    BackupNotFound { service: String, stamp: String },
139
140    #[error(
141        "service '{0}' does not declare backup support — the service author must set `backup = true` under [integrations] in its service.toml first"
142    )]
143    BackupNotSupported(String),
144
145    #[error("backup repository is not configured — run `ryra backup configure` first")]
146    BackupRepoNotConfigured,
147
148    #[error("backup is not enabled for service '{0}' — re-install with `ryra add {0} --backup`")]
149    BackupNotEnabled(String),
150
151    #[error(
152        "no snapshots found for service '{0}' in the backup repository — has `ryra backup run` ever succeeded?"
153    )]
154    BackupNoSnapshots(String),
155
156    #[error("restic command failed: {0}")]
157    Restic(String),
158
159    #[error("backup hook '{hook}' for service '{service}' failed: {message}")]
160    BackupHookFailed {
161        service: String,
162        hook: String,
163        message: String,
164    },
165
166    #[error(
167        "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"
168    )]
169    BackupVersionMismatch {
170        service: String,
171        backed_up: String,
172        current: String,
173    },
174}
175
176pub type Result<T> = std::result::Result<T, Error>;