@@ -29,13 +29,13 @@ pub mod impls;
29
29
30
30
use core:: { fmt:: Arguments , ops:: DerefMut } ;
31
31
32
- use postcard_schema:: Schema ;
33
- use serde:: Serialize ;
34
-
35
32
use crate :: {
36
33
header:: { VarHeader , VarKey , VarKeyKind , VarSeq } ,
37
34
DeviceMap , Key , TopicDirection ,
38
35
} ;
36
+ use postcard_schema:: Schema ;
37
+ use serde:: Serialize ;
38
+ use thiserror:: Error ;
39
39
40
40
//////////////////////////////////////////////////////////////////////////////
41
41
// TX
@@ -77,21 +77,24 @@ pub trait WireTx {
77
77
}
78
78
79
79
/// The base [`WireTx`] Error Kind
80
- #[ derive( Debug , Clone , Copy ) ]
80
+ #[ derive( Debug , Clone , Copy , Error ) ]
81
81
#[ non_exhaustive]
82
82
pub enum WireTxErrorKind {
83
83
/// The connection has been closed, and is unlikely to succeed until
84
84
/// the connection is re-established. This will cause the Server run
85
85
/// loop to terminate.
86
+ #[ error( "connection closed" ) ]
86
87
ConnectionClosed ,
87
88
/// Other unspecified errors
89
+ #[ error( "other" ) ]
88
90
Other ,
89
91
/// Timeout (WireTx impl specific) reached
92
+ #[ error( "timeout reached" ) ]
90
93
Timeout ,
91
94
}
92
95
93
96
/// A conversion trait to convert a user error into a base Kind type
94
- pub trait AsWireTxErrorKind {
97
+ pub trait AsWireTxErrorKind : core :: error :: Error {
95
98
/// Convert the error type into a base type
96
99
fn as_kind ( & self ) -> WireTxErrorKind ;
97
100
}
@@ -127,21 +130,24 @@ pub trait WireRx {
127
130
}
128
131
129
132
/// The base [`WireRx`] Error Kind
130
- #[ derive( Debug , Clone , Copy ) ]
133
+ #[ derive( Debug , Clone , Copy , Error ) ]
131
134
#[ non_exhaustive]
132
135
pub enum WireRxErrorKind {
133
136
/// The connection has been closed, and is unlikely to succeed until
134
137
/// the connection is re-established. This will cause the Server run
135
138
/// loop to terminate.
139
+ #[ error( "connection closed" ) ]
136
140
ConnectionClosed ,
137
141
/// The received message was too large for the server to handle
142
+ #[ error( "the received message was too large for the server to handle" ) ]
138
143
ReceivedMessageTooLarge ,
139
144
/// Other message kinds
145
+ #[ error( "other" ) ]
140
146
Other ,
141
147
}
142
148
143
149
/// A conversion trait to convert a user error into a base Kind type
144
- pub trait AsWireRxErrorKind {
150
+ pub trait AsWireRxErrorKind : core :: error :: Error {
145
151
/// Convert the error type into a base type
146
152
fn as_kind ( & self ) -> WireRxErrorKind ;
147
153
}
@@ -384,15 +390,18 @@ where
384
390
}
385
391
386
392
/// A type representing the different errors [`Server::run()`] may return
393
+ #[ derive( Debug , Error ) ]
387
394
pub enum ServerError < Tx , Rx >
388
395
where
389
396
Tx : WireTx ,
390
397
Rx : WireRx ,
391
398
{
392
399
/// A fatal error occurred with the [`WireTx::send()`] implementation
393
- TxFatal ( Tx :: Error ) ,
400
+ #[ error( "A fatal error occurred while transmitting" ) ]
401
+ TxFatal ( #[ source] Tx :: Error ) ,
394
402
/// A fatal error occurred with the [`WireRx::receive()`] implementation
395
- RxFatal ( Rx :: Error ) ,
403
+ #[ error( "A fatal error occurred while receiving" ) ]
404
+ RxFatal ( #[ source] Rx :: Error ) ,
396
405
}
397
406
398
407
impl < Tx , Rx , Buf , D > Server < Tx , Rx , Buf , D >
0 commit comments