-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.rs
93 lines (78 loc) · 2.1 KB
/
errors.rs
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
use pyo3::exceptions::PyException;
use pyo3::prelude::*;
use std::{error, fmt};
// KeyFileError
#[pyclass(extends=PyException)]
#[derive(Debug)]
pub struct KeyFileError {
pub message: String,
}
/// Error thrown when the keyfile is corrupt, non-writable, non-readable.
#[pymethods]
impl KeyFileError {
#[new]
#[pyo3(signature = (message=None))]
pub fn new(message: Option<String>) -> Self {
let msg = message.unwrap_or_default();
KeyFileError { message: msg }
}
pub fn __str__(&self) -> String {
self.message.clone()
}
}
impl fmt::Display for KeyFileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "KeyFileError: {}", self.message)
}
}
impl error::Error for KeyFileError {}
// ConfigurationError
#[pyclass(extends=PyException)]
#[derive(Debug)]
pub struct ConfigurationError {
pub message: String,
}
/// ConfigurationError
#[pymethods]
impl ConfigurationError {
#[new]
#[pyo3(signature = (message=None))]
pub fn new(message: Option<String>) -> Self {
let msg = message.unwrap_or_default();
ConfigurationError { message: msg }
}
pub fn __str__(&self) -> String {
self.message.clone()
}
}
impl fmt::Display for ConfigurationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ConfigurationError: {}", self.message)
}
}
impl error::Error for ConfigurationError {}
// PasswordError
#[pyclass(extends=PyException)]
#[derive(Debug)]
pub struct PasswordError {
pub message: String,
}
/// PasswordError occurs if the password used for decryption is invalid.
#[pymethods]
impl PasswordError {
#[new]
#[pyo3(signature = (message=None))]
pub fn new(message: Option<String>) -> Self {
let msg = message.unwrap_or_default();
PasswordError { message: msg }
}
pub fn __str__(&self) -> String {
self.message.clone()
}
}
impl fmt::Display for PasswordError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "PasswordError: {}", self.message)
}
}
impl error::Error for PasswordError {}