carefully check unwrap and expect usage

closes #59
I did not find any other cases where the unwrap or expect usage does not depend
on an internal invariant.
This commit is contained in:
Johann150 2021-05-24 12:23:21 +02:00
parent 92673c54fb
commit a4bafa2c4e
No known key found for this signature in database
GPG key ID: 9EE6577A2A06F8F1
3 changed files with 33 additions and 17 deletions

View file

@ -237,6 +237,7 @@ fn args() -> Result<Args> {
let certs = if reload_certs {
certificates::CertStore::load_from(&certs_path)?
} else {
// there must already have been certificates loaded
certs.unwrap()
};
@ -296,20 +297,25 @@ impl RequestHandle {
/// Creates a new request handle for the given stream. If establishing the TLS
/// session fails, returns a corresponding log line.
async fn new(stream: TcpStream, metadata: Arc<Mutex<FileOptions>>) -> Result<Self, String> {
let log_line = format!(
"{} {}",
stream.local_addr().unwrap(),
if ARGS.log_ips {
stream
.peer_addr()
.expect("could not get peer address")
.ip()
.to_string()
} else {
// Do not log IP address, but something else so columns still line up.
"-".into()
}
);
let local_addr = stream.local_addr().unwrap().to_string();
// try to get the remote IP address if desired
let peer_addr = if ARGS.log_ips {
stream
.peer_addr()
.or(Err(format!(
// use nonexistent status code 01 if peer IP is unknown
"{} - \"\" 01 \"IP error\" error:could not get peer address",
local_addr,
)))?
.ip()
.to_string()
} else {
// Do not log IP address, but something else so columns still line up.
"-".into()
};
let log_line = format!("{} {}", local_addr, peer_addr,);
match TLS.accept(stream).await {
Ok(stream) => Ok(Self {