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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#![allow(missing_docs)]
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("couldn't find `cargo`, which is a dependency of this cli (set 'PERSEUS_CARGO_PATH' to another location if you've installed it elsewhere)")]
CargoNotPresent {
#[source]
source: std::io::Error,
},
#[error(
"couldn't install `wasm32-unknown-unknown` target (do you have an internet connection?)"
)]
RustupTargetAddFailed { code: i32 },
#[error("couldn't get current directory (have you just deleted it?)")]
CurrentDirUnavailable {
#[source]
source: std::io::Error,
},
#[error(transparent)]
ExecutionError(#[from] ExecutionError),
#[error(transparent)]
ExportError(#[from] ExportError),
#[error(transparent)]
DeployError(#[from] DeployError),
#[error(transparent)]
WatchError(#[from] WatchError),
#[error(transparent)]
InitError(#[from] InitError),
#[error(transparent)]
NewError(#[from] NewError),
#[error(transparent)]
InstallError(#[from] InstallError),
}
#[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("couldn't get path to server executable (if this persists, try `perseus clean`)")]
GetServerExecutableFailedSimple,
#[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)")]
ServerExecutableMsgNotFound,
#[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("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,
},
#[error("couldn't parse `Cargo.toml` (are you running in the right directory?)")]
GetManifestFailed {
#[source]
source: cargo_toml::Error,
},
#[error("couldn't get crate name from `[package]` section of `Cargo.toml` (are you running in the right directory?)")]
CrateNameNotPresentInManifest,
#[error("couldn't create directory for distribution artifacts (do you have the necessary permissions?)")]
CreateDistFailed {
#[source]
source: std::io::Error,
},
}
#[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("couldn't copy directory from '{from}' to '{to}' for exporting")]
MoveDirFailed {
to: String,
from: String,
#[source]
source: fs_extra::error::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 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,
},
#[error("couldn't create distribution artifacts directory for deployment (if this persists, try `perseus clean`)")]
CreateDistDirFailed {
#[source]
source: std::io::Error,
},
#[error("failed to minify javascript bundle (this is probably an upstream bug, re-try with `--no-minify-js`)")]
MinifyError {
#[source]
source: minify_js::MinifyError,
},
#[error("minified js was not utf-8 (this is a bug, re-try with `--no-minify-js` for now)")]
MinifyNotUtf8 {
#[source]
source: std::string::FromUtf8Error,
},
#[error("failed to read unminified js (if this persists, try `perseus clean`)")]
ReadUnminifiedJsFailed {
#[source]
source: std::io::Error,
},
#[error("failed to write minified js (if this persists, try `perseus clean`)")]
WriteMinifiedJsFailed {
#[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("the file/folder '{filename}' could not be resolved to an absolute path (does the file/folder exist?)")]
WatchFileNotResolved {
filename: String,
source: std::io::Error,
},
#[error("couldn't watch file at '{filename}', try re-running the command")]
WatchFileFailed {
filename: String,
#[source]
source: notify::Error,
},
#[error("couldn't unwatch file at '{filename}', try re-running the command")]
UnwatchFileFailed {
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,
},
#[error("couldn't read an entry in the targeted custom directory for watching, do you have the necessary permissions?")]
ReadCustomDirEntryFailed {
#[source]
source: walkdir::Error,
},
}
#[derive(Error, Debug)]
pub enum InitError {
#[error("couldn't create directory structure for new project, do you have the necessary permissions?")]
CreateDirStructureFailed {
#[source]
source: std::io::Error,
},
#[error("couldn't create file '{filename}' for project initialization")]
CreateInitFileFailed {
#[source]
source: std::io::Error,
filename: String,
},
}
#[derive(Error, Debug)]
pub enum NewError {
#[error(transparent)]
InitError(#[from] InitError),
#[error("couldn't create directory for new project, do you have the necessary permissions?")]
CreateProjectDirFailed {
#[source]
source: std::io::Error,
},
#[error("fetching the custom initialization template failed")]
GetCustomInitFailed {
#[source]
source: ExecutionError,
},
#[error(
"fetching the custom initialization template returned non-zero exit code ({exit_code})"
)]
GetCustomInitNonZeroExitCode { exit_code: i32 },
#[error(
"couldn't remove git internals at '{target_dir:?}' for custom initialization template"
)]
RemoveCustomInitGitFailed {
target_dir: Option<String>,
#[source]
source: std::io::Error,
},
}
#[derive(Error, Debug)]
pub enum InstallError {
#[error("couldn't create `dist/tools/` for external dependency installation")]
CreateToolsDirFailed {
#[source]
source: std::io::Error,
},
#[error("couldn't install '{tool}', as there are no precompiled binaries for your platform and it's not currently installed; please install this tool manually (see https://framesurge.sh/perseus/en-US/docs/0.4.x/reference/faq)")]
ExternalToolUnavailable {
tool: String,
#[source]
source: std::io::Error,
},
#[error("couldn't download binary for '{tool}' (do you have an internet connection?)")]
BinaryDownloadRequestFailed {
tool: String,
#[source]
source: reqwest::Error,
},
#[error(
"couldn't create destination for tool download (do you have the necessary permissions?)"
)]
CreateToolDownloadDestFailed {
#[source]
source: tokio::io::Error,
},
#[error("couldn't chunk tool download properly (do you have an internet connection?)")]
ChunkBinaryDownloadFailed {
#[source]
source: reqwest::Error,
},
#[error(
"couldn't write downloaded chunk of external tool (do you have the necessary permissions?)"
)]
WriteBinaryDownloadChunkFailed {
#[source]
source: tokio::io::Error,
},
#[error("couldn't determine latest version of '{tool}' (do you have an internet connection?)")]
GetLatestToolVersionFailed {
tool: String,
#[source]
source: reqwest::Error,
},
#[error("couldn't parse latest version of '{tool}' (if this error persists, please report it as a bug)")]
ParseToolVersionFailed { tool: String },
#[error("couldn't create destination for extraction of external tool (do you have the necessary permissions?)")]
CreateToolExtractDestFailed {
#[source]
source: std::io::Error,
},
#[error("couldn't extract '{tool}' (do you have the necessary permissions?)")]
ToolExtractFailed {
tool: String,
#[source]
source: std::io::Error,
},
#[error("couldn't delete archive from tool deletion")]
ArchiveDeletionFailed {
#[source]
source: std::io::Error,
},
#[error("couldn't rename directory for external tool binaries")]
DirRenameFailed {
#[source]
source: std::io::Error,
},
#[error("couldn't read `dist/tools/` to determine which tool versions were installed (do you have the necessary permissions?)")]
ReadToolsDirFailed {
#[source]
source: std::io::Error,
},
#[error("directory found in `dist/tools/` with invalid name (running `perseus clean` should resolve this)")]
InvalidToolsDirName { name: String },
#[error("generating `Cargo.lock` returned non-zero exit code")]
LockfileGenerationNonZero { code: i32 },
#[error("couldn't generate `Cargo.lock`")]
LockfileGenerationFailed {
#[source]
source: ExecutionError,
},
#[error("couldn't fetch metadata for current crate (have you run `perseus init` yet?)")]
MetadataFailed {
#[source]
source: cargo_metadata::Error,
},
#[error("couldn't load `Cargo.lock` from workspace root")]
LockfileLoadFailed {
#[source]
source: cargo_lock::Error,
},
}