Repository navigation
Expand file tree
/
Copy patherror.rs
More file actions
482 lines (450 loc) · 15 KB
/
Copy patherror.rs
File metadata and controls
482 lines (450 loc) · 15 KB
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
use crate::comms::{ToMinionMessage, ToOverlordMessage};
use crate::people::PersonList;
use nostr_types::RelayUrl;
use std::panic::Location;
/// Error kinds that can occur in gossip-lib
#[derive(Debug)]
pub enum ErrorKind {
BadNostrConnectString,
BlossomError(String),
BroadcastSend(String),
BroadcastReceive(tokio::sync::broadcast::error::RecvError),
CannotUpdateRelayUrl,
Delegation(String),
Disconnected,
Empty(String),
EmptyJob,
EngageDisallowed,
EngagePending,
EventNotFound,
FromUtf8(std::string::FromUtf8Error),
General(String),
GroupDmsNotSupported,
HttpError(http::Error),
JoinError(tokio::task::JoinError),
KeyNotExportable,
KeySizeWrong,
KeyInvalid,
Lmdb(heed::Error),
MaxRelaysReached,
MpscSend(Box<tokio::sync::mpsc::error::SendError<ToOverlordMessage>>),
Nip05KeyNotFound,
Nip46CommandMissingId,
Nip46CommandNotJsonObject,
Nip46Denied,
Nip46NeedApproval,
Nip46ParsingError(String, String),
Nip46RelayNeeded,
Nostr(Box<nostr_types::Error>),
NoPrivateKey,
NoPublicKey,
NoRelay,
NotAPersonListEvent,
NoSlotsRemaining,
IdentityCannotSign,
IdentityCannotSignForAuth(RelayUrl),
Image(Box<image::error::ImageError>),
ImageFailure,
Io(std::io::Error),
Internal(String),
InvalidFilter,
InvalidUriParts(http::uri::InvalidUriParts),
InvalidDnsId,
InvalidUri(http::uri::InvalidUri),
InvalidUrl(String),
ListAllocationFailed,
ListAlreadyExists(PersonList),
ListEventMissingDtag,
ListIsNotEmpty,
ListIsWellKnown,
ListNotFound,
LoadMoreFailed,
NoRelays,
NoPeopleLeft,
NoProgress,
NostrConnectNotSetup,
Offline,
ParseInt(std::num::ParseIntError),
ParseBool(std::str::ParseBoolError),
RecordIsNotNewable,
Regex(regex::Error),
RelayRejectedUs,
ReqwestHttpError(reqwest::Error),
SerdeJson(serde_json::Error),
ShuttingDown,
SliceError(std::array::TryFromSliceError),
Speedy(speedy::Error),
Svg(Box<usvg::Error>),
TagNotIndexed(String),
Timeout(tokio::time::error::Elapsed),
TimedOut,
UnknownCommand(String),
UnsupportedRelayUsage,
UrlHasEmptyHostname,
UrlHasNoHostname,
UrlParse(url::ParseError),
Usage(String, String), // error, usage line
UsersCantUseNip17,
Utf8Error(std::str::Utf8Error),
Websocket(Box<tungstenite::Error>),
WrongEventKind,
}
/// Errors that can occur in gossip-lib, optionally including a file and line number
/// where they were generated
#[derive(Debug)]
pub struct Error {
pub kind: ErrorKind,
location: &'static Location<'static>,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}, {}", self.kind, self.location)
}
}
impl std::fmt::Display for ErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use ErrorKind::*;
match self {
BadNostrConnectString => write!(f, "Bad nostrconnect string"),
BlossomError(s) => write!(f, "Blossom error: {s}"),
BroadcastSend(s) => write!(f, "Error broadcasting: {s}"),
BroadcastReceive(e) => write!(f, "Error receiving broadcast: {e}"),
CannotUpdateRelayUrl => {
write!(f, "Cannot update relay url (create a new relay instead)")
}
Delegation(s) => write!(f, "NIP-26 Delegation Error: {s}"),
Disconnected => write!(f, "Disconnected"),
Empty(s) => write!(f, "{s} is empty"),
EmptyJob => write!(f, "relay job is empty"),
EngageDisallowed => write!(f, "relay is disallowed"),
EngagePending => write!(f, "relay approval is pending"),
EventNotFound => write!(f, "Event not found"),
FromUtf8(e) => write!(f, "UTF-8 error: {e}"),
GroupDmsNotSupported => write!(f, "Group DMs are not supported under NIP-04"),
General(s) => write!(f, "{s}"),
HttpError(e) => write!(f, "HTTP error: {e}"),
JoinError(e) => write!(f, "Task join error: {e}"),
KeyNotExportable => write!(f, "Key not exportable"),
KeySizeWrong => write!(f, "Key size is wrong"),
KeyInvalid => write!(f, "Key is invalid"),
Lmdb(e) => write!(f, "LMDB: {e}"),
MaxRelaysReached => write!(
f,
"Maximum relay connections reached, will not connect to another"
),
MpscSend(e) => write!(f, "Error sending mpsc: {e}"),
Nip05KeyNotFound => write!(f, "NIP-05 public key not found"),
Nip46CommandMissingId => write!(f, "NIP-46 command missing ID"),
Nip46CommandNotJsonObject => write!(f, "NIP-46 command not a json object"),
Nip46Denied => write!(f, "NIP-46 command denied"),
Nip46NeedApproval => write!(f, "NIP-46 approval needed"),
Nip46ParsingError(_id, e) => write!(f, "NIP-46 parse error: {e}"),
Nip46RelayNeeded => write!(f, "NIP-46 relay needed to respond."),
Nostr(e) => write!(f, "Nostr: {e}"),
NoPrivateKey => write!(f, "No private key is available."),
NoPublicKey => write!(f, "No public key identity available."),
NoRelay => write!(f, "Could not determine a relay to use."),
NotAPersonListEvent => write!(f, "Not a person list event"),
NoSlotsRemaining => write!(f, "No custom list slots remaining."),
IdentityCannotSign => write!(f, "Identity cannot sign."),
IdentityCannotSignForAuth(u) => {
write!(f, "Identity cannot sign, cannot AUTH to relay: {}", u)
}
Image(e) => write!(f, "Image: {e}"),
ImageFailure => write!(f, "Image Failure"),
Io(e) => write!(f, "I/O Error: {e}"),
Internal(s) => write!(f, "INTERNAL: {s}"),
InvalidFilter => write!(f, "Invalid filter"),
InvalidUriParts(e) => write!(f, "Invalid URI parts: {e}"),
InvalidDnsId => write!(f, "Invalid DNS ID (nip-05), should be user@domain"),
InvalidUri(e) => write!(f, "Invalid URI: {e}"),
InvalidUrl(s) => write!(f, "Invalid URL: {s}"),
ListAllocationFailed => write!(f, "List allocation failed (no more slots)"),
ListAlreadyExists(_) => write!(f, "List already exists"),
ListEventMissingDtag => write!(f, "List event missing d-tag"),
ListIsNotEmpty => write!(f, "List is not empty"),
ListIsWellKnown => write!(f, "List is well known and cannot be deallocated"),
ListNotFound => write!(f, "List was not found"),
LoadMoreFailed => write!(f, "Load more failed"),
NoRelays => write!(f, "No relays"),
NoPeopleLeft => write!(f, "No people left"),
NoProgress => write!(f, "No progress"),
NostrConnectNotSetup => write!(f, "NostrConnect not setup, cannot connect"),
Offline => write!(f, "Offline"),
ParseInt(e) => write!(f, "Bad integer: {e}"),
ParseBool(e) => write!(f, "Bad bool: {e}"),
RecordIsNotNewable => write!(f, "Record is not newable"),
Regex(e) => write!(f, "Regex: {e}"),
RelayRejectedUs => write!(f, "Relay rejected us."),
ReqwestHttpError(e) => write!(f, "HTTP (reqwest) error: {e}"),
SerdeJson(e) => write!(f, "SerdeJson Error: {e}"),
ShuttingDown => write!(f, "Shutting down"),
SliceError(e) => write!(f, "Slice: {e}"),
Speedy(e) => write!(f, "Speedy: {e}"),
Svg(e) => write!(f, "SVG: {e}"),
TagNotIndexed(s) => write!(f, "Tag not indexed: {s}"),
Timeout(e) => write!(f, "Timeout: {e}"),
TimedOut => write!(f, "Timed out"),
UnknownCommand(s) => write!(f, "Unknown command: {s}"),
UnsupportedRelayUsage => write!(f, "Unsupported relay usage"),
UrlHasEmptyHostname => write!(f, "URL has empty hostname"),
UrlHasNoHostname => write!(f, "URL has no hostname"),
UrlParse(e) => write!(f, "URL parse: {e}"),
Usage(e, u) => write!(f, "{}\n\nUsage: {}", e, u),
UsersCantUseNip17 => write!(f, "User(s) can't use NIP-17 DMs"),
Utf8Error(e) => write!(f, "UTF-8 error: {e}"),
Websocket(e) => write!(f, "Websocket: {e}"),
WrongEventKind => write!(f, "Wrong event kind"),
}
}
}
// Note: we impl Into because our typical pattern is InnerError::Variant.into()
// when we tried implementing From, the location was deep in rust code's
// blanket into implementation, which wasn't the line number we wanted.
//
// As for converting other error types, the try! macro uses From so it
// is correct.
#[allow(clippy::from_over_into)]
impl Into<Error> for ErrorKind {
#[track_caller]
fn into(self) -> Error {
Error {
kind: self,
location: Location::caller(),
}
}
}
impl From<tokio::sync::broadcast::error::SendError<ToMinionMessage>> for Error {
#[track_caller]
fn from(e: tokio::sync::broadcast::error::SendError<ToMinionMessage>) -> Error {
Error {
kind: ErrorKind::BroadcastSend(format!("{}", e)),
location: Location::caller(),
}
}
}
impl From<tokio::sync::broadcast::error::RecvError> for Error {
#[track_caller]
fn from(e: tokio::sync::broadcast::error::RecvError) -> Error {
Error {
kind: ErrorKind::BroadcastReceive(e),
location: Location::caller(),
}
}
}
impl From<String> for Error {
#[track_caller]
fn from(s: String) -> Error {
Error {
kind: ErrorKind::General(s),
location: Location::caller(),
}
}
}
impl From<&str> for Error {
#[track_caller]
fn from(s: &str) -> Error {
Error {
kind: ErrorKind::General(s.to_string()),
location: Location::caller(),
}
}
}
impl From<http::Error> for Error {
#[track_caller]
fn from(e: http::Error) -> Error {
Error {
kind: ErrorKind::HttpError(e),
location: Location::caller(),
}
}
}
impl From<tokio::task::JoinError> for Error {
#[track_caller]
fn from(e: tokio::task::JoinError) -> Error {
Error {
kind: ErrorKind::JoinError(e),
location: Location::caller(),
}
}
}
impl From<tokio::sync::mpsc::error::SendError<ToOverlordMessage>> for Error {
#[track_caller]
fn from(e: tokio::sync::mpsc::error::SendError<ToOverlordMessage>) -> Error {
Error {
kind: ErrorKind::MpscSend(Box::new(e)),
location: Location::caller(),
}
}
}
impl From<nostr_types::Error> for Error {
#[track_caller]
fn from(e: nostr_types::Error) -> Error {
Error {
kind: ErrorKind::Nostr(Box::new(e)),
location: Location::caller(),
}
}
}
impl From<image::error::ImageError> for Error {
#[track_caller]
fn from(e: image::error::ImageError) -> Error {
Error {
kind: ErrorKind::Image(Box::new(e)),
location: Location::caller(),
}
}
}
impl From<std::io::Error> for Error {
#[track_caller]
fn from(e: std::io::Error) -> Error {
Error {
kind: ErrorKind::Io(e),
location: Location::caller(),
}
}
}
impl From<http::uri::InvalidUriParts> for Error {
#[track_caller]
fn from(e: http::uri::InvalidUriParts) -> Error {
Error {
kind: ErrorKind::InvalidUriParts(e),
location: Location::caller(),
}
}
}
impl From<http::uri::InvalidUri> for Error {
#[track_caller]
fn from(e: http::uri::InvalidUri) -> Error {
Error {
kind: ErrorKind::InvalidUri(e),
location: Location::caller(),
}
}
}
impl From<heed::Error> for Error {
#[track_caller]
fn from(e: heed::Error) -> Error {
Error {
kind: ErrorKind::Lmdb(e),
location: Location::caller(),
}
}
}
impl From<std::num::ParseIntError> for Error {
#[track_caller]
fn from(e: std::num::ParseIntError) -> Error {
Error {
kind: ErrorKind::ParseInt(e),
location: Location::caller(),
}
}
}
impl From<std::str::ParseBoolError> for Error {
#[track_caller]
fn from(e: std::str::ParseBoolError) -> Self {
Error {
kind: ErrorKind::ParseBool(e),
location: Location::caller(),
}
}
}
impl From<regex::Error> for Error {
#[track_caller]
fn from(e: regex::Error) -> Error {
Error {
kind: ErrorKind::Regex(e),
location: Location::caller(),
}
}
}
impl From<reqwest::Error> for Error {
#[track_caller]
fn from(e: reqwest::Error) -> Error {
Error {
kind: ErrorKind::ReqwestHttpError(e),
location: Location::caller(),
}
}
}
impl From<serde_json::Error> for Error {
#[track_caller]
fn from(e: serde_json::Error) -> Error {
Error {
kind: ErrorKind::SerdeJson(e),
location: Location::caller(),
}
}
}
impl From<std::array::TryFromSliceError> for Error {
#[track_caller]
fn from(e: std::array::TryFromSliceError) -> Error {
Error {
kind: ErrorKind::SliceError(e),
location: Location::caller(),
}
}
}
impl From<speedy::Error> for Error {
#[track_caller]
fn from(e: speedy::Error) -> Error {
Error {
kind: ErrorKind::Speedy(e),
location: Location::caller(),
}
}
}
impl From<usvg::Error> for Error {
#[track_caller]
fn from(e: usvg::Error) -> Error {
Error {
kind: ErrorKind::Svg(Box::new(e)),
location: Location::caller(),
}
}
}
impl From<tokio::time::error::Elapsed> for Error {
#[track_caller]
fn from(e: tokio::time::error::Elapsed) -> Error {
Error {
kind: ErrorKind::Timeout(e),
location: Location::caller(),
}
}
}
impl From<std::str::Utf8Error> for Error {
#[track_caller]
fn from(e: std::str::Utf8Error) -> Error {
Error {
kind: ErrorKind::Utf8Error(e),
location: Location::caller(),
}
}
}
impl From<tungstenite::Error> for Error {
#[track_caller]
fn from(e: tungstenite::Error) -> Error {
Error {
kind: ErrorKind::Websocket(Box::new(e)),
location: Location::caller(),
}
}
}
impl From<url::ParseError> for Error {
#[track_caller]
fn from(e: url::ParseError) -> Error {
Error {
kind: ErrorKind::UrlParse(e),
location: Location::caller(),
}
}
}
impl From<std::string::FromUtf8Error> for Error {
#[track_caller]
fn from(e: std::string::FromUtf8Error) -> Error {
Error {
kind: ErrorKind::FromUtf8(e),
location: Location::caller(),
}
}
}