Skip to content

Commit b435713

Browse files
committed
Implement std::error::Error trait for ttrpc Error
Use Crate thiserror. Signed-off-by: Tim Zhang <[email protected]>
1 parent e71de77 commit b435713

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ libc = { version = "0.2.59", features = [ "extra_traits" ] }
1717
nix = "0.16.1"
1818
log = "0.4"
1919
byteorder = "1.3.2"
20+
thiserror = "1.0"
2021

2122
async-trait = { version = "0.1.31", optional = true }
2223
tokio = { version = "0.2", features = ["rt-threaded", "sync", "uds", "stream", "macros", "io-util"], optional = true }

src/error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616
1717
use crate::ttrpc::{Code, Status};
1818
use std::result;
19+
use thiserror::Error;
1920

2021
/// The error type for ttrpc.
21-
#[derive(Debug)]
22+
#[derive(Error, Debug)]
2223
pub enum Error {
24+
#[error("socket err: {0}")]
2325
Socket(String),
26+
27+
#[error("rpc status: {0:?}")]
2428
RpcStatus(Status),
29+
30+
#[error("ttrpc err: {0}")]
2531
Others(String),
2632
}
2733

0 commit comments

Comments
 (0)