netconf/message/
error.rs

1use super::rpc;
2
3#[derive(Debug, thiserror::Error)]
4#[error("failed to deserialize message content from XML")]
5pub enum Read {
6    Xml(#[from] quick_xml::Error),
7
8    /// UTF-8 decoding failed.
9    #[error("failed to decode utf-8")]
10    DecodeMessage(#[from] std::str::Utf8Error),
11
12    /// Failed to parse a [`MessageId`][rpc::MessageId].
13    #[error("failed to parse message-id")]
14    MessageIdParse(#[source] std::num::ParseIntError),
15
16    #[error("failed to parse session-id")]
17    SessionIdParse(#[source] std::num::ParseIntError),
18
19    #[error("unexpected event while parsing xml: {0:?}")]
20    UnexpectedXmlEvent(quick_xml::events::Event<'static>),
21
22    #[error("message-id attribute missing in rpc-reply")]
23    NoMessageId,
24
25    #[error("message-id mis-match between parse phases. please file a bug report!")]
26    MessageIdMismatch {
27        initial: rpc::MessageId,
28        new: rpc::MessageId,
29    },
30
31    #[error("missing '{element}' element while parsing '{msg_type}' message")]
32    MissingElement {
33        msg_type: &'static str,
34        element: &'static str,
35    },
36
37    #[error("encountered an unknown rpc-error error-type: {0}")]
38    UnknownErrorType(String),
39
40    #[error("encountered an unknown rpc-error error-tag: {0}")]
41    UnknownErrorTag(String),
42
43    #[error("encountered an unknown rpc-error error-severity: {0}")]
44    UnknownErrorSeverity(String),
45
46    #[error("encountered an unknown rpc-error error-info type: {0}")]
47    UnknownErrorInfo(String),
48
49    #[error("failed to parse capability URI")]
50    ParseCapability(#[from] iri_string::validate::Error),
51
52    Other(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
53}
54
55impl Read {
56    pub(super) const fn missing_element(msg_type: &'static str, element: &'static str) -> Self {
57        Self::MissingElement { msg_type, element }
58    }
59
60    pub(super) const fn message_id_mismatch(initial: rpc::MessageId, new: rpc::MessageId) -> Self {
61        Self::MessageIdMismatch { initial, new }
62    }
63}
64
65#[derive(Debug, thiserror::Error)]
66#[error("failed to serialize message content as XML")]
67pub enum Write {
68    Xml(#[from] quick_xml::Error),
69
70    /// UTF-8 encoding failed.
71    #[error("failed to utf-8 encode message")]
72    EncodeMessage(#[from] std::string::FromUtf8Error),
73
74    Other(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
75}