link_cli/protocol/
error.rs1use links_notation::binary::BinaryError;
4use std::io;
5use thiserror::Error;
6
7#[derive(Debug, Error)]
10pub enum ProtocolError {
11 #[error("I/O error: {0}")]
13 Io(#[from] io::Error),
14
15 #[error("malformed message: {0}")]
17 Malformed(String),
18
19 #[error("invalid LiNo: {0}")]
21 InvalidLino(String),
22
23 #[error("limit exceeded: {0}")]
25 LimitExceeded(String),
26
27 #[error("cannot encode: {0}")]
29 Unencodable(String),
30
31 #[error("server error: {0}")]
33 Remote(String),
34}
35
36impl ProtocolError {
37 pub(crate) fn malformed(message: impl Into<String>) -> Self {
38 Self::Malformed(message.into())
39 }
40}
41
42impl From<BinaryError> for ProtocolError {
45 fn from(error: BinaryError) -> Self {
46 match error {
47 BinaryError::Io(error) => Self::Io(error),
48 BinaryError::Malformed(detail) => Self::Malformed(detail),
49 BinaryError::InvalidLino(detail) => Self::InvalidLino(detail),
50 BinaryError::LimitExceeded(detail) => Self::LimitExceeded(detail),
51 BinaryError::Unencodable(detail) => Self::Unencodable(detail),
52 }
53 }
54}
55
56pub type ProtocolResult<T> = Result<T, ProtocolError>;