Skip to content

Commit 6cba073

Browse files
authored
add missing impl Error for HostErr (#132)
use `thiserror` to do this as it's already used in the crate. this updates it from v1 to v2 and also uses it in `no_std` environments as that's now supported by `thiserror`.
1 parent 1e50837 commit 6cba073

File tree

10 files changed

+32
-44
lines changed

10 files changed

+32
-44
lines changed

example/esp32c6-serial/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/firmware-eusb-v0_3/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/firmware-eusb-v0_4/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/firmware/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/nrf52840-serial/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/serial-host/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/workbook-host/Cargo.lock

Lines changed: 5 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/postcard-rpc-test/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/postcard-rpc/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ version = "0.3.69"
6464
optional = true
6565

6666
[dependencies.thiserror]
67-
version = "1.0"
68-
optional = true
67+
version = "2"
68+
default-features = false
6969

7070
[dependencies.web-sys]
7171

@@ -195,7 +195,7 @@ use-std = [
195195
"dep:tokio",
196196
"postcard/use-std",
197197
"postcard-schema/use-std",
198-
"dep:thiserror",
198+
"thiserror/std",
199199
"dep:tracing",
200200
"dep:trait-variant",
201201
"dep:ssmarshal",

source/postcard-rpc/src/host_client/mod.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::{
1313
Arc, RwLock,
1414
},
1515
};
16-
1716
use thiserror::Error;
1817

1918
use maitake_sync::{
@@ -52,28 +51,26 @@ pub(crate) mod util;
5251
pub mod test_channels;
5352

5453
/// Host Error Kind
55-
#[derive(Debug, PartialEq)]
54+
#[derive(Debug, PartialEq, Error)]
5655
pub enum HostErr<WireErr> {
5756
/// An error of the user-specified wire error type
57+
#[error("a wire error occurred")]
5858
Wire(WireErr),
5959
/// We got a response that didn't match the expected value or the
6060
/// user specified wire error type
6161
///
6262
/// This is also (misused) to report when duplicate sequence numbers
6363
/// in-flight at the same time are detected.
64+
#[error("the response received didn't match the expected value or the wire error type")]
6465
BadResponse,
6566
/// Deserialization of the message failed
66-
Postcard(postcard::Error),
67+
#[error("message deserialization failed")]
68+
Postcard(#[from] postcard::Error),
6769
/// The interface has been closed, and no further messages are possible
70+
#[error("the interface has been closed, and no further messages are possible")]
6871
Closed,
6972
}
7073

71-
impl<T> From<postcard::Error> for HostErr<T> {
72-
fn from(value: postcard::Error) -> Self {
73-
Self::Postcard(value)
74-
}
75-
}
76-
7774
impl<T> From<WaitError> for HostErr<T> {
7875
fn from(_: WaitError) -> Self {
7976
Self::Closed
@@ -230,17 +227,23 @@ where
230227
}
231228

232229
/// Errors related to retrieving the schema
233-
#[derive(Debug)]
230+
#[derive(Debug, Error)]
234231
pub enum SchemaError<WireErr> {
235232
/// Some kind of communication error occurred
236-
Comms(HostErr<WireErr>),
233+
#[error("A communication error occurred")]
234+
Comms(#[from] HostErr<WireErr>),
237235
/// An error occurred internally. Please open an issue.
236+
#[error("An error occurred internally. Please open an issue.")]
238237
TaskError,
239238
/// Invalid report data was received, including endpoints or
240239
/// tasks that referred to unknown types. Please open an issue
240+
#[error("Invalid report data was received. Please open an issue.")]
241241
InvalidReportData,
242242
/// Data was lost while transmitting. If a retry does not solve
243243
/// this, please open an issue.
244+
#[error(
245+
"Data was lost while transmitting. If a retry does not solve this, please open an issue."
246+
)]
244247
LostData,
245248
}
246249

0 commit comments

Comments
 (0)