feat(error): revamp hyper::Error type

**The `Error` is now an opaque struct**, which allows for more variants to
be added freely, and the internal representation to change without being
breaking changes.

For inspecting an `Error`, there are several `is_*` methods to check for
certain classes of errors, such as `Error::is_parse()`. The `cause` can
also be inspected, like before. This likely seems like a downgrade, but
more inspection can be added as needed!

The `Error` now knows about more states, which gives much more context
around when a certain error occurs. This is also expressed in the
description and `fmt` messages.

**Most places where a user would provide an error to hyper can now pass
any error type** (`E: Into<Box<std::error::Error>>`). This error is passed
back in relevant places, and can be useful for logging. This should make
it much clearer about what error a user should provide to hyper: any it
feels is relevant!

Closes #1128
Closes #1130
Closes #1431
Closes #1338

BREAKING CHANGE: `Error` is no longer an enum to pattern match over, or
  to construct. Code will need to be updated accordingly.

  For body streams or `Service`s, inference might be unable to determine
  what error type you mean to return. Starting in Rust 1.26, you could
  just label that as `!` if you never return an error.
This commit is contained in:
Sean McArthur
2018-04-10 14:29:34 -07:00
parent 33874f9a75
commit 5d3c472228
22 changed files with 519 additions and 407 deletions

View File

@@ -35,7 +35,7 @@ fn retryable_request() {
try_ready!(sock1.read(&mut [0u8; 512]));
try_ready!(sock1.write(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
Ok(Async::Ready(()))
});
}).map_err(|e: ::std::io::Error| panic!("srv1 poll_fn error: {}", e));
res1.join(srv1).wait().expect("res1");
}
drop(sock1);
@@ -52,7 +52,7 @@ fn retryable_request() {
try_ready!(sock2.read(&mut [0u8; 512]));
try_ready!(sock2.write(b"HTTP/1.1 222 OK\r\nContent-Length: 0\r\n\r\n"));
Ok(Async::Ready(()))
});
}).map_err(|e: ::std::io::Error| panic!("srv2 poll_fn error: {}", e));
res2.join(srv2).wait().expect("res2");
}
@@ -82,7 +82,7 @@ fn conn_reset_after_write() {
try_ready!(sock1.read(&mut [0u8; 512]));
try_ready!(sock1.write(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
Ok(Async::Ready(()))
});
}).map_err(|e: ::std::io::Error| panic!("srv1 poll_fn error: {}", e));
res1.join(srv1).wait().expect("res1");
}
@@ -105,10 +105,10 @@ fn conn_reset_after_write() {
try_ready!(sock1.as_mut().unwrap().read(&mut [0u8; 512]));
sock1.take();
Ok(Async::Ready(()))
});
}).map_err(|e: ::std::io::Error| panic!("srv2 poll_fn error: {}", e));
let err = res2.join(srv2).wait().expect_err("res2");
match err {
::Error::Incomplete => (),
match err.kind() {
&::error::Kind::Incomplete => (),
other => panic!("expected Incomplete, found {:?}", other)
}
}