USB: P0 fix — eliminate runtime panics in usbscsid main loop

IMPROVEMENT-PLAN.md §10.1.6: critical safety fix.

usbscsid main.rs had 3 runtime unwrap sites that would panic
the daemon on transient errors:

1. Line 106: debug block 0 read on init — now uses if-let to
   skip the debug print if the read fails (disconnected device,
   media error). The device still registers its scheme.

2. Line 144: event_queue event unwrap — now handles Err()
   with eprintln + continue instead of panic.

3. Line 147: scheme.tick() unwrap — now handles Err()
   with eprintln instead of panic.

Scheme tick failures propagate gracefully — the event loop
continues, the daemon survives. This matches the Linux 7.1
pattern of logging USB errors without crashing the daemon.
This commit is contained in:
Red Bear OS
2026-07-08 00:31:03 +03:00
parent 9f61f7bf68
commit 11ef817366
+16 -6
View File
@@ -103,8 +103,9 @@ fn daemon(daemon: daemon::Daemon) -> ! {
}
let mut buffer = [0u8; 512];
scsi.read(&mut *protocol, 0, &mut buffer).unwrap();
println!("DISK CONTENT: {}", base64::encode(&buffer[..]));
if let Ok(()) = scsi.read(&mut *protocol, 0, &mut buffer).map(|_| ()) {
println!("DISK CONTENT: {}", base64::encode(&buffer[..]));
}
let event_queue = event::EventQueue::new().unwrap();
@@ -141,10 +142,19 @@ fn daemon(daemon: daemon::Daemon) -> ! {
.unwrap();
for event in event_queue {
match event.unwrap().user_data {
Event::Scheme => driver_block::FuturesExecutor
.block_on(scheme.tick())
.unwrap(),
let event = match event {
Ok(e) => e,
Err(e) => {
eprintln!("usbscsid: event error: {}", e);
continue;
}
};
match event.user_data {
Event::Scheme => {
if let Err(e) = driver_block::FuturesExecutor.block_on(scheme.tick()) {
eprintln!("usbscsid: scheme tick error: {}", e);
}
}
}
}