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("tailscale: {0}")]
71    Tailscale(String),
72
73    #[error("directory creation failed for {path}: {source}")]
74    DirCreate {
75        path: PathBuf,
76        source: std::io::Error,
77    },
78
79    #[error("template rendering failed: {0}")]
80    Template(String),
81
82    #[error(
83        "auth integration requires an auth provider to be configured first — run `ryra add authelia`"
84    )]
85    AuthNotConfigured,
86
87    #[error("service {0} does not support native OIDC auth")]
88    NoOidcSupport(String),
89
90    #[error(
91        "authelia is local-only at {auth_url}, but {service} will be reachable at \
92         {service_url}. Off-host clients (e.g., other devices on your tailnet) can't \
93         resolve `*.internal` hostnames, so the OIDC redirect from {service} back \
94         to authelia would fail.\n\n\
95         Fix: re-install authelia at the same exposure as {service}:\n  \
96         ryra remove authelia --purge\n  \
97         ryra add authelia --tailscale  (or --url <public-https-url>)"
98    )]
99    AuthExposureMismatch {
100        auth_url: String,
101        service: String,
102        service_url: String,
103    },
104
105    #[error("{0}")]
106    UnsupportedArchitecture(String),
107
108    #[error("service '{service}' has no env_group named '{group}'{hint}")]
109    UnknownEnvGroup {
110        service: String,
111        group: String,
112        hint: String,
113    },
114
115    #[error("`ryra configure` can't change {field} for service '{service}'. {workaround}")]
116    ConfigureUnsupported {
117        service: String,
118        field: String,
119        workaround: String,
120    },
121
122    #[error("could not determine home directory: set $HOME")]
123    HomeDirNotFound,
124
125    #[error("invalid service reference: {0}")]
126    InvalidServiceRef(String),
127
128    #[error("registry configuration error: {0}")]
129    RegistryConfig(String),
130
131    #[error("quadlet bundle error: {0}")]
132    Bundle(String),
133
134    #[error("auth context error: {0}")]
135    AuthContext(String),
136
137    #[error("config validation failed: {0}")]
138    ConfigValidation(String),
139
140    #[error(
141        "{service}: {} hand-edited file(s) would be overwritten — re-run with --force to overwrite, or back up your changes first:\n  {}",
142        paths.len(),
143        paths.iter().map(|p| p.display().to_string()).collect::<Vec<_>>().join("\n  ")
144    )]
145    HandEditedFiles {
146        service: String,
147        paths: Vec<PathBuf>,
148    },
149
150    #[error("no backups found for service '{0}' — `ryra upgrade` creates them, run that first")]
151    NoBackup(String),
152
153    #[error(
154        "service '{service}' has no backup at timestamp {stamp} — run `ryra revert {service}` to use the most recent"
155    )]
156    BackupNotFound { service: String, stamp: String },
157
158    #[error(
159        "service '{0}' does not declare backup support — the service author must set `backup = true` under [integrations] in its service.toml first"
160    )]
161    BackupNotSupported(String),
162
163    #[error("backup repository is not configured — run `ryra backup configure` first")]
164    BackupRepoNotConfigured,
165
166    #[error("backup is not enabled for service '{0}' — re-install with `ryra add {0} --backup`")]
167    BackupNotEnabled(String),
168
169    #[error(
170        "no snapshots found for service '{0}' in the backup repository — has `ryra backup run` ever succeeded?"
171    )]
172    BackupNoSnapshots(String),
173
174    #[error("restic command failed: {0}")]
175    Restic(String),
176
177    #[error("backup hook '{hook}' for service '{service}' failed: {message}")]
178    BackupHookFailed {
179        service: String,
180        hook: String,
181        message: String,
182    },
183
184    #[error(
185        "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"
186    )]
187    BackupVersionMismatch {
188        service: String,
189        backed_up: String,
190        current: String,
191    },
192}
193
194pub type Result<T> = std::result::Result<T, Error>;