@@ -29,13 +29,13 @@ pub mod impls;
2929
3030use core:: { fmt:: Arguments , ops:: DerefMut } ;
3131
32- use postcard_schema:: Schema ;
33- use serde:: Serialize ;
34-
3532use crate :: {
3633 header:: { VarHeader , VarKey , VarKeyKind , VarSeq } ,
3734 DeviceMap , Key , TopicDirection ,
3835} ;
36+ use postcard_schema:: Schema ;
37+ use serde:: Serialize ;
38+ use thiserror:: Error ;
3939
4040//////////////////////////////////////////////////////////////////////////////
4141// TX
@@ -77,21 +77,24 @@ pub trait WireTx {
7777}
7878
7979/// The base [`WireTx`] Error Kind
80- #[ derive( Debug , Clone , Copy ) ]
80+ #[ derive( Debug , Clone , Copy , Error ) ]
8181#[ non_exhaustive]
8282pub enum WireTxErrorKind {
8383 /// The connection has been closed, and is unlikely to succeed until
8484 /// the connection is re-established. This will cause the Server run
8585 /// loop to terminate.
86+ #[ error( "connection closed" ) ]
8687 ConnectionClosed ,
8788 /// Other unspecified errors
89+ #[ error( "other" ) ]
8890 Other ,
8991 /// Timeout (WireTx impl specific) reached
92+ #[ error( "timeout reached" ) ]
9093 Timeout ,
9194}
9295
9396/// A conversion trait to convert a user error into a base Kind type
94- pub trait AsWireTxErrorKind {
97+ pub trait AsWireTxErrorKind : core :: error :: Error {
9598 /// Convert the error type into a base type
9699 fn as_kind ( & self ) -> WireTxErrorKind ;
97100}
@@ -127,21 +130,24 @@ pub trait WireRx {
127130}
128131
129132/// The base [`WireRx`] Error Kind
130- #[ derive( Debug , Clone , Copy ) ]
133+ #[ derive( Debug , Clone , Copy , Error ) ]
131134#[ non_exhaustive]
132135pub enum WireRxErrorKind {
133136 /// The connection has been closed, and is unlikely to succeed until
134137 /// the connection is re-established. This will cause the Server run
135138 /// loop to terminate.
139+ #[ error( "connection closed" ) ]
136140 ConnectionClosed ,
137141 /// The received message was too large for the server to handle
142+ #[ error( "the received message was too large for the server to handle" ) ]
138143 ReceivedMessageTooLarge ,
139144 /// Other message kinds
145+ #[ error( "other" ) ]
140146 Other ,
141147}
142148
143149/// A conversion trait to convert a user error into a base Kind type
144- pub trait AsWireRxErrorKind {
150+ pub trait AsWireRxErrorKind : core :: error :: Error {
145151 /// Convert the error type into a base type
146152 fn as_kind ( & self ) -> WireRxErrorKind ;
147153}
@@ -384,15 +390,18 @@ where
384390}
385391
386392/// A type representing the different errors [`Server::run()`] may return
393+ #[ derive( Debug , Error ) ]
387394pub enum ServerError < Tx , Rx >
388395where
389396 Tx : WireTx ,
390397 Rx : WireRx ,
391398{
392399 /// 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 ) ,
394402 /// 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 ) ,
396405}
397406
398407impl < Tx , Rx , Buf , D > Server < Tx , Rx , Buf , D >
0 commit comments