Avoid panic on invalid addr

This commit is contained in:
Vincent Prouillet 2021-06-24 22:36:51 +02:00
parent e62664b4ff
commit 0cd1ea9537

View file

@ -286,7 +286,10 @@ pub fn serve(
console::report_elapsed_time(start); console::report_elapsed_time(start);
// Stop right there if we can't bind to the address // Stop right there if we can't bind to the address
let bind_address: SocketAddrV4 = address.parse().unwrap(); let bind_address: SocketAddrV4 = match address.parse() {
Ok(a) => a,
Err(_) => return Err(format!("Invalid address: {}.", address).into())
};
if (TcpListener::bind(&bind_address)).is_err() { if (TcpListener::bind(&bind_address)).is_err() {
return Err(format!("Cannot start server on address {}.", address).into()); return Err(format!("Cannot start server on address {}.", address).into());
} }