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
|
use crate::software::{SoftwareModule, SoftwareName, SoftwareType, SoftwareVersion};
use csv;
use serde::{Deserialize, Serialize};
#[derive(thiserror::Error, Debug)]
pub enum TopicError {
#[error("Topic {topic} is unknown.")]
UnknownTopic { topic: String },
}
#[derive(thiserror::Error, Debug, Clone, Deserialize, Serialize, Eq, PartialEq)]
pub enum SoftwareError {
#[error("DownloadError error: {reason:?} for {url:?}")]
DownloadError { reason: String, url: String },
#[error("Failed to finalize updates for {software_type:?}")]
Finalize {
software_type: SoftwareType,
reason: String,
},
#[error("Failed to install {module:?}")]
Install {
module: SoftwareModule,
reason: String,
},
#[error("Failed to list modules for {software_type:?}")]
ListError {
software_type: SoftwareType,
reason: String,
},
#[error("JSON parse error: {reason:?}")]
ParseError { reason: String },
#[error("Plugin error for {software_type:?}, reason: {reason:?}")]
Plugin {
software_type: SoftwareType,
reason: String,
},
#[error("Failed to prepare updates for {software_type:?}")]
Prepare {
software_type: SoftwareType,
reason: String,
},
#[error("Failed to uninstall {module:?}")]
Remove {
module: SoftwareModule,
reason: String,
},
#[error("Failed to execute updates for {software_type:?}")]
UpdateList {
software_type: SoftwareType,
reason: String,
},
#[error("Unknown {software_type:?} module: {name:?}")]
UnknownModule {
software_type: SoftwareType,
name: SoftwareName,
},
#[error("Unknown software type: {software_type:?}")]
UnknownSoftwareType { software_type: SoftwareType },
#[error("Unexpected module type: {actual:?}, should be: {expected:?}")]
WrongModuleType {
actual: SoftwareType,
expected: SoftwareType,
},
#[error("Unknown {software_type:?} version: {name:?} - {version:?}")]
UnknownVersion {
software_type: SoftwareType,
name: SoftwareName,
version: SoftwareVersion,
},
#[error("The configured default plugin: {0} not found")]
InvalidDefaultPlugin(String),
#[error("The update-list command is not supported by this: {0} plugin")]
UpdateListNotSupported(String),
#[error("I/O error: {reason:?}")]
IoError { reason: String },
#[error("CSV error: {reason:?}")]
FromCSV { reason: String },
}
impl From<serde_json::Error> for SoftwareError {
fn from(err: serde_json::Error) -> Self {
SoftwareError::ParseError {
reason: format!("{}", err),
}
}
}
impl From<std::io::Error> for SoftwareError {
fn from(err: std::io::Error) -> Self {
SoftwareError::IoError {
reason: format!("{}", err),
}
}
}
impl From<csv::Error> for SoftwareError {
fn from(err: csv::Error) -> Self {
SoftwareError::FromCSV {
reason: format!("{}", err),
}
}
}
|