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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#![allow(missing_docs)]
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
PrepError(#[from] PrepError),
#[error(transparent)]
ExecutionError(#[from] ExecutionError),
#[error(transparent)]
EjectionError(#[from] EjectionError),
#[error(transparent)]
ExportError(#[from] ExportError),
#[error(transparent)]
DeployError(#[from] DeployError),
#[error(transparent)]
WatchError(#[from] WatchError),
}
#[derive(Error, Debug)]
pub enum PrepError {
#[error("prerequisite command execution failed for prerequisite '{cmd}' (set '{env_var}' to another location if you've installed it elsewhere)")]
PrereqNotPresent {
cmd: String,
env_var: String,
#[source]
source: std::io::Error,
},
#[error("couldn't get current directory (have you just deleted it?)")]
CurrentDirUnavailable {
#[source]
source: std::io::Error,
},
#[error("couldn't extract internal subcrates to '{target_dir:?}' (do you have the necessary permissions?)")]
ExtractionFailed {
target_dir: Option<String>,
#[source]
source: std::io::Error,
},
#[error("updating gitignore to ignore `.perseus/` failed (`.perseus/` has been automatically deleted)")]
GitignoreUpdateFailed {
#[source]
source: std::io::Error,
},
#[error("couldn't update internal manifest file at '{target_dir:?}' (`.perseus/` has been automatically deleted)")]
ManifestUpdateFailed {
target_dir: Option<String>,
#[source]
source: std::io::Error,
},
#[error("couldn't get `Cargo.toml` for your project (have you run `cargo init` yet?)")]
GetUserManifestFailed {
#[source]
source: cargo_toml::Error,
},
#[error(
"your project's `Cargo.toml` doesn't have a `[package]` section (package name is required)"
)]
MalformedUserManifest,
#[error("couldn't remove corrupted `.perseus/` directory as required by previous error (please delete `.perseus/` manually)")]
RemoveBadDirFailed {
#[source]
source: std::io::Error,
},
}
pub fn err_should_cause_deletion(err: &Error) -> bool {
matches!(
err,
Error::PrepError(
PrepError::ExtractionFailed { .. }
| PrepError::GitignoreUpdateFailed { .. }
| PrepError::ManifestUpdateFailed { .. }
)
)
}
#[derive(Error, Debug)]
pub enum ExecutionError {
#[error("couldn't execute command '{cmd}' (this doesn't mean it threw an error, it means it couldn't be run at all)")]
CmdExecFailed {
cmd: String,
#[source]
source: std::io::Error,
},
#[error("couldn't execute command because it prematurely stopped reporting (if this persists, please report it as a bug)")]
NextStdoutLineNone,
#[error("couldn't get path to server executable (if this persists, please report it as a bug, especially if you've just updated `cargo`)")]
GetServerExecutableFailed {
#[source]
source: serde_json::Error,
},
#[error("expected second-last message from Cargo to contain server executable path, none existed (too few messages) (report this as a bug if it persists)")]
ServerExectutableMsgNotFound,
#[error("couldn't parse server executable path from Cargo (report this as a bug if it persists): {err}")]
ParseServerExecutableFailed { err: String },
#[error("couldn't remove and replace internal build artifact directory '{target:?}' (run `perseus clean` if this persists)")]
RemoveArtifactsFailed {
target: Option<String>,
#[source]
source: std::io::Error,
},
#[error("couldn't move `.perseus/pkg/` to `.perseus/dist/pkg/` (run `perseus clean` if this persists)")]
MovePkgDirFailed {
#[source]
source: std::io::Error,
},
#[error("failed to wait on thread (please report this as a bug if it persists)")]
ThreadWaitFailed,
#[error("value in `PORT` environment variable couldn't be parsed as a number")]
PortNotNumber {
#[source]
source: std::num::ParseIntError,
},
}
#[derive(Error, Debug)]
pub enum EjectionError {
#[error("couldn't remove perseus subcrates from gitignore for ejection")]
GitignoreUpdateFailed {
#[source]
source: std::io::Error,
},
#[error("line `.perseus/` to remove not found in `.gitignore`")]
GitignoreLineNotPresent,
#[error("couldn't write ejection declaration file (`.perseus/.ejected`), please try again")]
DeclarationWriteFailed {
#[source]
source: std::io::Error,
},
#[error("can't clean after ejection unless `--force` is provided (maybe you meant to use `--dist`?)")]
CleanAfterEject,
#[error("can't tinker after ejection unless `--force` is provided (ejecting and using plugins can be problematic depending on the plugins used)")]
TinkerAfterEject,
}
#[derive(Error, Debug)]
pub enum ExportError {
#[error("couldn't create directory structure necessary for exporting (do you have the necessary permissions?)")]
DirStructureCreationFailed {
#[source]
source: std::io::Error,
},
#[error("couldn't copy asset from '{from}' to '{to}' for exporting")]
MoveAssetFailed {
to: String,
from: String,
#[source]
source: std::io::Error,
},
#[error(transparent)]
ExecutionError(#[from] ExecutionError),
}
#[derive(Error, Debug)]
pub enum DeployError {
#[error("couldn't copy exported static files from '{from:?}' to '{to}'")]
MoveExportDirFailed {
to: String,
from: String,
#[source]
source: fs_extra::error::Error,
},
#[error("couldn't delete and recreate output directory '{path}'")]
ReplaceOutputDirFailed {
path: String,
#[source]
source: std::io::Error,
},
#[error("couldn't get path to server executable (if this persists, try `perseus clean`)")]
GetServerExecutableFailed,
#[error("couldn't copy file from '{from}' to '{to}' for deployment packaging")]
MoveAssetFailed {
to: String,
from: String,
#[source]
source: std::io::Error,
},
#[error("couldn't copy directory from '{from}' to '{to}' for deployment packaging")]
MoveDirFailed {
to: String,
from: String,
#[source]
source: fs_extra::error::Error,
},
#[error("couldn't read contents of export directory '{path}' for packaging (if this persists, try `perseus clean`)")]
ReadExportDirFailed {
path: String,
#[source]
source: std::io::Error,
},
}
#[derive(Error, Debug)]
pub enum WatchError {
#[error("couldn't set up a file watcher, try re-running this command")]
WatcherSetupFailed {
#[source]
source: notify::Error,
},
#[error("couldn't read your current directory to watch files, do you have the necessary permissions?")]
ReadCurrentDirFailed {
#[source]
source: std::io::Error,
},
#[error("couldn't read entry in your current directory, try re-running this command")]
ReadDirEntryFailed {
#[source]
source: std::io::Error,
},
#[error("couldn't watch file at '{filename}', try re-running the command")]
WatchFileFailed {
filename: String,
#[source]
source: notify::Error,
},
#[error("an error occurred while watching files")]
WatcherError {
#[source]
source: std::sync::mpsc::RecvError,
},
#[error("couldn't spawn a child process to build your app in watcher mode")]
SpawnSelfFailed {
#[source]
source: std::io::Error,
},
#[error("couldn't get the path to the cli's executable, try re-running the command")]
GetSelfPathFailed {
#[source]
source: std::io::Error,
},
}