document panics better

This commit is contained in:
soruh 2023-03-19 17:21:00 +01:00
parent 96033a0796
commit d917afe58c
3 changed files with 12 additions and 10 deletions

View File

@ -310,7 +310,9 @@ pub async fn handler(
info!(%addr, number, port, "authenticated");
let listener = handler_metadata.listener.as_mut().unwrap(); // we are only authenticated if this is set
let Some(listener) = handler_metadata.listener.as_mut() else {
unreachable!("client sucessfully authenticated but did not set handler_metadata.listener");
};
packet.header = Header {
kind: PacketKind::RemConfirm.raw(),

View File

@ -1,5 +1,5 @@
#![warn(clippy::pedantic)]
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
#![allow(clippy::missing_errors_doc)]
use std::{
fmt::Debug,

View File

@ -228,7 +228,7 @@ impl PortState {
pub fn new_state(&mut self, status: PortStatus) {
self.last_change = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.expect("timestamp overflow")
.as_secs();
self.status = status;
@ -354,11 +354,9 @@ impl PortHandler {
let port_guard = Rejector::start(listener, packet);
assert!(
self.port_guards.insert(port, port_guard).is_none(),
"Tried to start rejector that is already running.
This should have been impossible since it requires two listeners on the same port."
);
if self.port_guards.insert(port, port_guard).is_some() {
unreachable!("Tried to start rejector that is already running. This should have been impossible since it requires two listeners on the same port.");
}
Ok(())
}
@ -451,7 +449,9 @@ impl PortHandler {
self.try_recover_port(config)?
};
assert!(self.allocated_ports.insert(number, port).is_none());
if self.allocated_ports.insert(number, port).is_some() {
unreachable!("allocated port twice");
}
Some(port)
};
@ -529,7 +529,7 @@ impl PortHandler {
self.errored_ports.insert((
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.expect("timestamp overflow")
.as_secs(),
port,
));