commit 44caf77badaa4ece36cca13ae9a791da7751898e
parent b56c5bd6caeee53c4cd9f5e99099e4215eee6294
Author: triesap <tyson@radroots.org>
Date: Thu, 16 Jul 2026 09:35:19 +0000
net: make NetError clone non-panicking
- preserve Io variant display and kind when cloning
- cover non-panicking Io clones in radroots_net tests
- remove panic-based clone expectation from error coverage
- keep NetError clone total for call sites that clone errors
Diffstat:
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/crates/net/src/error.rs b/crates/net/src/error.rs
@@ -53,8 +53,8 @@ impl Clone for NetError {
NetError::Msg(m) => NetError::Msg(m.clone()),
NetError::Poisoned => NetError::Poisoned,
#[cfg(feature = "std")]
- NetError::Io(_) => {
- panic!("cannot clone std::io::Error");
+ NetError::Io(error) => {
+ NetError::Io(std::io::Error::new(error.kind(), error.to_string()))
}
NetError::MissingKey => NetError::MissingKey,
NetError::InvalidHex32 => NetError::InvalidHex32,
diff --git a/crates/net/tests/error.rs b/crates/net/tests/error.rs
@@ -1,5 +1,4 @@
use radroots_net::error::NetError;
-use std::panic::{AssertUnwindSafe, catch_unwind};
#[test]
fn msg_constructor_creates_msg_variant() {
@@ -29,10 +28,10 @@ fn clone_covers_non_io_variants() {
}
#[test]
-fn clone_panics_for_io_variant() {
+fn clone_preserves_io_variant_without_panicking() {
let io_err = NetError::Io(std::io::Error::other("io"));
- let result = catch_unwind(AssertUnwindSafe(|| {
- let _ = io_err.clone();
- }));
- assert!(result.is_err());
+ let cloned = io_err.clone();
+
+ assert!(matches!(cloned, NetError::Io(_)));
+ assert_eq!(format!("{io_err}"), format!("{cloned}"));
}