♻️ Fix unwrap()s in ptth_core.

Some were in an unused function, so I removed that function.

Some were in graceful_shutdown and can't really be handled. So I made
them into "expect"s
main
_ 2020-11-29 16:36:59 +00:00
parent 5f9e84f7f6
commit 3e74f2b1ef
2 changed files with 3 additions and 21 deletions

View File

@ -25,7 +25,7 @@ pub fn init () -> oneshot::Receiver <()> {
let tx = tx.replace (None); let tx = tx.replace (None);
if let Some (tx) = tx { if let Some (tx) = tx {
tx.send (()).unwrap (); tx.send (()).expect ("Error sending Ctrl-C to program");
} }
}).expect ("Error setting Ctrl-C handler"); }).expect ("Error setting Ctrl-C handler");
@ -72,8 +72,8 @@ impl ForcedShutdown {
server: F server: F
) -> Result <T, ShutdownError> { ) -> Result <T, ShutdownError> {
let fut = async move { let fut = async move {
self.rx.await.unwrap (); self.rx.await.expect ("Error awaiting graceful shutdown signal");
self.tx.send (()).unwrap (); self.tx.send (()).expect ("Error forwarding graceful shutdown signal");
let timeout = 5; let timeout = 5;
debug! ("Starting graceful shutdown. Forcing shutdown in {} seconds", timeout); debug! ("Starting graceful shutdown. Forcing shutdown in {} seconds", timeout);
delay_for (Duration::from_secs (timeout)).await; delay_for (Duration::from_secs (timeout)).await;

View File

@ -154,24 +154,6 @@ pub struct Response {
} }
impl Response { impl Response {
pub async fn into_bytes (self) -> Vec <u8> {
let mut body = match self.body {
None => return Vec::new (),
Some (x) => x,
};
let mut result = match self.content_length {
None => Vec::new (),
Some (x) => Vec::with_capacity (x.try_into ().unwrap ()),
};
while let Some (Ok (mut chunk)) = body.recv ().await {
result.append (&mut chunk);
}
result
}
pub fn status_code (&mut self, c: StatusCode) -> &mut Self { pub fn status_code (&mut self, c: StatusCode) -> &mut Self {
self.parts.status_code = c; self.parts.status_code = c;
self self