-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
36 lines (32 loc) · 1.13 KB
/
error.rs
File metadata and controls
36 lines (32 loc) · 1.13 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
use crate::communication::CommunicationError;
#[derive(Debug, thiserror::Error)]
pub enum CommandError {
#[error("Non-recoverable: {0:?}")]
NonRecoverable(anyhow::Error),
#[error("External: {0:?}")]
External(anyhow::Error),
#[error("Protocol Violation: {0:?}")]
ProtocolViolation(anyhow::Error),
}
impl From<std::io::Error> for CommandError {
fn from(e: std::io::Error) -> Self {
CommandError::NonRecoverable(e.into())
}
}
impl From<subprocess::PopenError> for CommandError {
fn from(e: subprocess::PopenError) -> Self {
CommandError::NonRecoverable(e.into())
}
}
impl From<CommunicationError> for CommandError {
fn from(e: CommunicationError) -> Self {
match e {
CommunicationError::PacketInvalidError => CommandError::External(e.into()),
CommunicationError::TimedOut
| CommunicationError::NotAcknowledged
| CommunicationError::CepParsing(_)
| CommunicationError::TooManyBytes => CommandError::ProtocolViolation(e.into()),
CommunicationError::Io(_) => CommandError::NonRecoverable(e.into()),
}
}
}