feat(tonic): implement From<io::Error> for Status (#500)
Implements the conversion from `std::io::Error` to `tonic::Status`. **Motivation:** The `io::Error` conversion is currently left as unimplemented. It either should be implemented or removed if it won't be implemented. **Solution:** Implements the conversion from `std::io::Error` to `tonic::Status`
This commit is contained in:
+23
-2
@@ -572,8 +572,29 @@ impl From<Status> for h2::Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::io::Error> for Status {
|
impl From<std::io::Error> for Status {
|
||||||
fn from(_io: std::io::Error) -> Self {
|
fn from(err: std::io::Error) -> Self {
|
||||||
unimplemented!()
|
use std::io::ErrorKind;
|
||||||
|
let code = match err.kind() {
|
||||||
|
ErrorKind::BrokenPipe
|
||||||
|
| ErrorKind::WouldBlock
|
||||||
|
| ErrorKind::WriteZero
|
||||||
|
| ErrorKind::Interrupted => Code::Internal,
|
||||||
|
ErrorKind::ConnectionRefused
|
||||||
|
| ErrorKind::ConnectionReset
|
||||||
|
| ErrorKind::NotConnected
|
||||||
|
| ErrorKind::AddrInUse
|
||||||
|
| ErrorKind::AddrNotAvailable => Code::Unavailable,
|
||||||
|
ErrorKind::AlreadyExists => Code::AlreadyExists,
|
||||||
|
ErrorKind::ConnectionAborted => Code::Aborted,
|
||||||
|
ErrorKind::InvalidData => Code::DataLoss,
|
||||||
|
ErrorKind::InvalidInput => Code::InvalidArgument,
|
||||||
|
ErrorKind::NotFound => Code::NotFound,
|
||||||
|
ErrorKind::PermissionDenied => Code::PermissionDenied,
|
||||||
|
ErrorKind::TimedOut => Code::DeadlineExceeded,
|
||||||
|
ErrorKind::UnexpectedEof => Code::OutOfRange,
|
||||||
|
_ => Code::Unknown,
|
||||||
|
};
|
||||||
|
Status::new(code, err.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user