alpine_protocol_sdk/
error.rs

1use alpine::handshake::HandshakeError;
2use alpine::stream::StreamError;
3use thiserror::Error;
4
5use crate::transport::TransportError;
6
7/// Errors emitted by the SDK runtime.
8#[derive(Error, Debug)]
9pub enum AlpineSdkError {
10    #[error("transport error: {0}")]
11    Transport(#[from] TransportError),
12
13    #[error("connection timed out")]
14    Timeout,
15
16    #[error("discovery failed: {0}")]
17    DiscoveryFailed(String),
18
19    #[error("invalid discovery reply")]
20    InvalidDiscoveryReply,
21
22    #[error("handshake already in progress")]
23    HandshakeAlreadyInProgress,
24
25    #[error("discovery not allowed once handshake has begun")]
26    DiscoveryAfterHandshake,
27
28    #[error("invalid phase transition: {0}")]
29    InvalidPhaseTransition(String),
30
31    #[error("missing client_nonce")]
32    MissingClientNonce,
33
34    #[error("handshake failed: {0}")]
35    HandshakeFailed(String),
36
37    #[error("device identity verification failed")]
38    IdentityVerificationFailed,
39
40    #[error("io error: {0}")]
41    Io(String),
42
43    #[error("no active session")]
44    NoActiveSession,
45
46    #[error("session expired")]
47    SessionExpired,
48
49    #[error("streaming not supported by device")]
50    StreamingNotSupported,
51
52    #[error("invalid channel value")]
53    InvalidChannelValue,
54
55    #[error("internal error: {0}")]
56    Internal(String),
57}
58
59impl From<HandshakeError> for AlpineSdkError {
60    fn from(err: HandshakeError) -> Self {
61        match err {
62            HandshakeError::Transport(_) => AlpineSdkError::HandshakeFailed(err.to_string()),
63            other => AlpineSdkError::HandshakeFailed(other.to_string()),
64        }
65    }
66}
67
68impl From<StreamError> for AlpineSdkError {
69    fn from(err: StreamError) -> Self {
70        AlpineSdkError::Internal(err.to_string())
71    }
72}