rosrust/tcpros/
error.rs
1error_chain::error_chain! {
2 foreign_links {
3 Io(::std::io::Error);
4 }
5 errors {
6 ServiceConnectionFail(service: String) {
7 description("Failed to connect to service")
8 display("Failed to connect with client to service {}", service)
9 }
10 TopicConnectionFail(topic:String) {
11 description("Failed to connect to topic")
12 display("Failed to connect to topic '{}'", topic)
13 }
14 HeaderMismatch(field: String, expected: String, actual: String) {
15 description("Data field within header mismatched")
16 display("Data field '{}' within header mismatched. Expected: '{}' Actual: '{}'",
17 field, expected, actual)
18 }
19 HeaderMissingField(field: String) {
20 description("Data field within header missing")
21 display("Data field '{}' within header missing", field)
22 }
23 MessageTypeMismatch(expected: String, actual: String) {
24 description("Cannot publish with multiple message types")
25 display("Cannot publish '{}' data on '{}' publisher", actual, expected)
26 }
27 ServiceResponseInterruption {
28 description("Data stream interrupted while reading service response")
29 display("Data stream interrupted while reading service response")
30 }
31 ServiceResponseUnknown {
32 description("Unknown error caused service response to panic")
33 display("Unknown error caused service response to panic")
34 }
35 }
36}
37
38#[inline]
39fn is_closed_connection(err: &::std::io::Error) -> bool {
40 use std::io::ErrorKind as IoErrorKind;
41 matches!(
42 err.kind(),
43 IoErrorKind::BrokenPipe | IoErrorKind::ConnectionReset,
44 )
45}
46
47impl Error {
48 pub fn is_closed_connection(&self) -> bool {
49 match *self.kind() {
50 ErrorKind::Io(ref io_err) => is_closed_connection(io_err),
51 _ => false,
52 }
53 }
54}