1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use std::path::PathBuf;
use thiserror::Error;
use printnanny_api_client::apis::accounts_api;
use printnanny_api_client::apis::devices_api;
use printnanny_api_client::apis::octoprint_api;
use printnanny_api_client::apis::Error as ApiError;
#[derive(Error, Debug)]
pub enum PrintNannyConfigError {
#[error("Failed to load license from {pattern:?}. Please download a license from https://printnanny.ai/dashboard/ and save to /boot")]
PatternNotFound { pattern: String },
#[error("Refusing to overwrite existing file at {path:?}.")]
FileExists { path: PathBuf },
#[error("PRINTNANNY_CONFIG was set {path:?} but file was not found")]
ConfigFileNotFound { path: PathBuf },
#[error("Failed to unpack file {filename} from archive {archive:?}")]
ArchiveMissingFile { filename: String, archive: PathBuf },
#[error("Failed to read {path:?}. Please download a license from https://printnanny.ai/dashboard/ and save to ")]
LicenseMissing { path: String },
#[error("Command {cmd} exited with code {code:?} stdout: {stdout} stderr: {stderr}")]
CommandError {
cmd: String,
code: Option<i32>,
stdout: String,
stderr: String,
},
#[error("Failed to write {path} - {error}")]
WriteIOError {
path: PathBuf,
error: std::io::Error,
},
#[error("Failed to read {path} - {error}")]
ReadIOError {
path: PathBuf,
error: std::io::Error,
},
#[error("Failed to copy {src:?} to {dest:?} - {error}")]
CopyIOError {
src: PathBuf,
dest: PathBuf,
error: std::io::Error,
},
#[error("Failed to parse OctoPrintServer field: {field} {detail:?}")]
OctoPrintServerConfigError {
field: String,
detail: Option<String>,
},
#[error("Failed to handle invalid config value {value:?}")]
InvalidValue { value: String },
#[error("Refusing to overwrite existing keypair at {path:?}.")]
KeypairExists { path: PathBuf },
#[error(transparent)]
JsonSerError(#[from] serde_json::Error),
#[error(transparent)]
TomlSerError(#[from] toml::ser::Error),
#[error(transparent)]
FigmentError(#[from] figment::error::Error),
#[error(transparent)]
ZipError(#[from] zip::result::ZipError),
#[error(transparent)]
IoError(#[from] std::io::Error),
#[error("Setup incomplete, failed to read {field:?} {detail:?}")]
SetupIncomplete {
detail: Option<String>,
field: String,
},
}
#[derive(Error, Debug)]
pub enum ServiceError {
#[error(transparent)]
JsonSerError(#[from] serde_json::Error),
#[error(transparent)]
TomlSerError(#[from] toml::ser::Error),
#[error(transparent)]
PisRetrieveError(#[from] ApiError<devices_api::PisRetrieveError>),
#[error(transparent)]
PisPartialUpdateError(#[from] ApiError<devices_api::PisPartialUpdateError>),
#[error(transparent)]
SystemInfoCreateError(#[from] ApiError<devices_api::PisSystemInfoCreateError>),
#[error(transparent)]
SystemInfoUpdateOrCreateError(#[from] ApiError<devices_api::SystemInfoUpdateOrCreateError>),
#[error(transparent)]
OctoprintPartialUpdateError(#[from] ApiError<octoprint_api::OctoprintPartialUpdateError>),
#[error(transparent)]
FromUtf8Error(#[from] std::string::FromUtf8Error),
#[error(transparent)]
UserRetrieveError(#[from] ApiError<accounts_api::AccountsUserRetrieveError>),
#[error(transparent)]
Accounts2faAuthTokenCreateError(
#[from] ApiError<accounts_api::Accounts2faAuthTokenCreateError>,
),
#[error(transparent)]
Accounts2faAuthEmailCreateError(
#[from] ApiError<accounts_api::Accounts2faAuthEmailCreateError>,
),
#[error(transparent)]
Utf8Error(#[from] std::str::Utf8Error),
#[error("License fingerprint mismatch (expected {expected:?}, found {active:?})")]
InvalidLicense { expected: String, active: String },
#[error("Failed to fingerprint {path:?} got stderr {stderr:?}")]
FingerprintError { path: PathBuf, stderr: String },
#[error(transparent)]
ProcError(#[from] procfs::ProcError),
#[error(transparent)]
SysInfoError(#[from] sys_info::Error),
#[error(transparent)]
IoError(#[from] std::io::Error),
#[error(transparent)]
FigmentError(#[from] figment::error::Error),
#[error(transparent)]
PrintNannyConfigError(#[from] PrintNannyConfigError),
#[error("Setup incomplete, failed to read {field:?} {detail:?}")]
SetupIncomplete {
detail: Option<String>,
field: String,
},
}