Skip to content

Commit

Permalink
chore: Change several panics to warn messages
Browse files Browse the repository at this point in the history
A lot of these can fire as the system spins down, and will crash
  • Loading branch information
qdot committed Mar 17, 2024
1 parent 5b2bc6d commit baafa2c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
Expand Up @@ -9,10 +9,8 @@ use super::lovense_connect_service_hardware::LovenseServiceHardwareConnector;
use crate::{
core::errors::ButtplugDeviceError,
server::device::hardware::communication::{
HardwareCommunicationManager,
HardwareCommunicationManagerBuilder,
HardwareCommunicationManagerEvent,
TimedRetryCommunicationManager,
HardwareCommunicationManager, HardwareCommunicationManagerBuilder,
HardwareCommunicationManagerEvent, TimedRetryCommunicationManager,
TimedRetryCommunicationManagerImpl,
},
};
Expand Down Expand Up @@ -140,13 +138,19 @@ pub(super) async fn get_local_info(host: &str) -> Option<LovenseServiceLocalInfo
return None;
}

let text = res
.text()
.await
.expect("If we got a 200 back, we should at least have text.");
let info: LovenseServiceLocalInfo = serde_json::from_str(&text)
.expect("Should always get json back from service, if we got a response.");
Some(info)
match res.text().await {
Ok(text) => match serde_json::from_str(&text) {
Ok(info) => Some(info),
Err(e) => {
warn!("Should always get json back from service, if we got a response: ${e}");
None
}
},
Err(e) => {
warn!("If we got a 200 back, we should at least have text: ${e}");
None
}
}
}
Err(err) => {
error!(
Expand Down
Expand Up @@ -139,11 +139,13 @@ impl ChannelHub {
}

pub async fn send_output(&self, msg: OutgoingLovenseData) {
self
if self
.dongle_outgoing
.send(msg)
.await
.expect("Won't get here without owner being alive.");
.is_err() {
warn!("Dongle message sent without owner being alive, assuming shutdown.");
}
}

pub async fn send_event(&self, msg: HardwareCommunicationManagerEvent) {
Expand Down Expand Up @@ -254,11 +256,13 @@ impl LovenseDongleState for LovenseDongleWaitForDongle {
self.is_scanning.store(false, Ordering::SeqCst);
should_scan = false;
// If we were requested to scan and then asked to stop, act like we at least tried.
self
if self
.event_sender
.send(HardwareCommunicationManagerEvent::ScanningFinished)
.await
.expect("Won't get here without owner being alive.");
.is_err() {
warn!("Dongle message sent without owner being alive, assuming shutdown.");
}
}
}
}
Expand Down Expand Up @@ -660,10 +664,14 @@ impl LovenseDongleState for LovenseDongleDeviceLoop {
}
}
}
_ => device_read_sender
_ => {
if device_read_sender
.send(dongle_msg)
.await
.expect("Won't get here if the parent isn't alive."),
.is_err() {
warn!("Dongle message sent without owner being alive, assuming shutdown.");
}
}
}
}
IncomingMessage::CommMgr(comm_msg) => match comm_msg {
Expand Down
Expand Up @@ -260,13 +260,15 @@ impl LovenseHIDDongleCommunicationManager {

*(held_read_thread.lock().await) = Some(read_thread);
*(held_write_thread.lock().await) = Some(write_thread);
machine_sender_clone
if machine_sender_clone
.send(LovenseDeviceCommand::DongleFound(
writer_sender,
reader_receiver,
))
.await
.expect("We've already spun up the state machine so we know this receiver exists.");
.is_err() {
warn!("We've already spun up the state machine, this receiver should exist, but if we're shutting down this will throw.");
}
info!("Found Lovense HID Dongle");
Ok(())
}
Expand Down
Expand Up @@ -312,10 +312,12 @@ impl HardwareInternal for SerialPortHardware {
let data = msg.data.clone();
// TODO Should check endpoint validity
async move {
sender
if sender
.send(data)
.await
.expect("Tasks should exist if we get here.");
.is_err() {
warn!("Tasks should exist if we get here, but may not if we're shutting down");
}
Ok(())
}
.boxed()
Expand Down

0 comments on commit baafa2c

Please sign in to comment.