diff --git a/examples/discover_printers.rs b/examples/discover_printers.rs index cbd201c..32e9560 100644 --- a/examples/discover_printers.rs +++ b/examples/discover_printers.rs @@ -69,7 +69,12 @@ async fn main() -> anyhow::Result<()> { // picking one would mean probing a network nobody named. None => println!("(no subnet given, so no sweep - pass one like 192.168.0.0/24 to include it)"), } - found.extend(list_serial()?); + // Not `?`: serial listing reads Linux sysfs and fails on any other + // OS, and that must not throw away what the listen and sweep found. + match list_serial() { + Ok(ports) => found.extend(ports), + Err(err) => println!("(serial ports skipped: {err})"), + } found } "listen" | "raw" => { diff --git a/src/discovery/serial.rs b/src/discovery/serial.rs index 4610c19..e25a603 100644 --- a/src/discovery/serial.rs +++ b/src/discovery/serial.rs @@ -485,6 +485,7 @@ mod tests { /// The one part of serial discovery this environment can demonstrate: /// with no ports attached it finds none, and does not error doing it. + #[cfg(target_os = "linux")] #[test] fn listing_ports_where_there_are_none_is_empty_and_not_an_error() { let ports = list_ports().expect("sysfs exists on this host"); @@ -492,4 +493,14 @@ mod tests { assert!(port.path.starts_with("/dev/"), "{port:?}"); } } + + /// Port listing reads Linux sysfs, so elsewhere it must say so rather + /// than report "no ports" - which would look like a clean scan (found on + /// Windows CI, run 415, where the Linux test above failed). + #[cfg(not(target_os = "linux"))] + #[test] + fn listing_ports_off_linux_is_an_error_not_an_empty_list() { + let err = list_ports().expect_err("there is no sysfs here"); + assert!(err.to_string().contains("not a Linux host"), "{err}"); + } }