1use crate::model::SlmpCommand;
2
3#[derive(Debug, Clone, thiserror::Error)]
4#[error("{message}")]
5pub struct SlmpError {
6 pub message: String,
7 pub end_code: Option<u16>,
8 pub command: Option<SlmpCommand>,
9 pub subcommand: Option<u16>,
10}
11
12impl SlmpError {
13 pub fn new(message: impl Into<String>) -> Self {
14 Self {
15 message: message.into(),
16 end_code: None,
17 command: None,
18 subcommand: None,
19 }
20 }
21
22 pub fn with_context(
23 message: impl Into<String>,
24 end_code: Option<u16>,
25 command: Option<SlmpCommand>,
26 subcommand: Option<u16>,
27 ) -> Self {
28 Self {
29 message: message.into(),
30 end_code,
31 command,
32 subcommand,
33 }
34 }
35}
36
37impl From<std::io::Error> for SlmpError {
38 fn from(value: std::io::Error) -> Self {
39 Self::new(value.to_string())
40 }
41}