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
mod ffi;
pub mod plugin;
use std::{
io, error::Error,
fmt::{ self, Display, Formatter }
};
pub use crate::plugin::Plugin;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum ErrorKind {
PermissionDenied{ requires_authentication: bool },
AccessDenied{ retries_left: Option<u64> },
IoError,
InvalidData,
ItemNotFound,
InvalidParameter{ index: u64 },
OperationCancelled,
OperationTimedOut,
OtherPluginError{ errno: u64 },
Unsupported
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct KyncError {
pub kind: ErrorKind,
pub desc: Option<String>
}
impl Display for KyncError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{:?}", &self.kind)?;
if let Some(desc) = self.desc.as_ref() { write!(f, " ({:#?})", desc)?; }
Ok(())
}
}
impl From<ErrorKind> for KyncError {
fn from(kind: ErrorKind) -> Self {
Self{ kind, desc: None }
}
}
impl<T: ToString> From<(ErrorKind, T)> for KyncError {
fn from(kind_desc: (ErrorKind, T)) -> Self {
Self{ kind: kind_desc.0, desc: Some(kind_desc.1.to_string()) }
}
}
impl From<io::ErrorKind> for KyncError {
fn from(io_error_kind: io::ErrorKind) -> Self {
Self{ kind: ErrorKind::IoError, desc: Some(format!("{:#?}", io_error_kind)) }
}
}
impl From<io::Error> for KyncError {
fn from(io_error: io::Error) -> Self {
Self{ kind: ErrorKind::IoError, desc: Some(format!("{}", io_error)) }
}
}
impl Error for KyncError {}