Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Handle errors when starting parity (#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw authored and gavofyork committed Jun 27, 2016
1 parent 6859152 commit 1fdbfa1
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions signer/src/ws_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,17 @@ impl Server {
// Spawn a thread with event loop
let handle = thread::spawn(move || {
ph.catch_panic(move || {
ws.listen(addr).unwrap()
match ws.listen(addr).map_err(ServerError::from) {
Err(ServerError::IoError(io)) => die(format!(
"Signer: Could not start listening on specified address. Make sure that no other instance is running on Signer's port. Details: {:?}",
io
)),
Err(any_error) => die(format!(
"Signer: Unknown error occured when starting Signer. Details: {:?}",
any_error
)),
Ok(server) => server,
}
}).unwrap()
});

Expand All @@ -123,7 +133,11 @@ impl Server {
// TODO [ToDr] Some better structure here for messages.
broadcaster.send("new_message").unwrap();
}).expect("It's the only place we are running start_listening. It shouldn't fail.");
broadcaster.shutdown().expect("Broadcaster should close gently.")
let res = broadcaster.shutdown();

if let Err(e) = res {
warn!("Signer: Broadcaster was not closed cleanly. Details: {:?}", e);
}
}).unwrap()
});

Expand All @@ -148,5 +162,11 @@ impl Drop for Server {
self.queue.finish();
self.broadcaster_handle.take().unwrap().join().unwrap();
self.handle.take().unwrap().join().unwrap();

}
}

fn die(msg: String) -> ! {
println!("ERROR: {}", msg);
std::process::exit(1);
}

0 comments on commit 1fdbfa1

Please sign in to comment.