From 0d22edc72000fcb90ad878c3d90796fccbe78e10 Mon Sep 17 00:00:00 2001 From: undivisible <136312656+undivisible@users.noreply.github.com> Date: Thu, 10 Sep 2026 15:28:08 +0000 Subject: [PATCH 1/2] refactor(uf2): replace unwrap with ? in tests Updated test signatures in `in-cli/src/native_emit/uf2.rs` to return `Result<(), Box>` and replaced unsafe `unwrap()` calls on `try_into()` with the `?` operator. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- in-cli/src/native_emit/uf2.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/in-cli/src/native_emit/uf2.rs b/in-cli/src/native_emit/uf2.rs index e398aa35..1bdae6f0 100644 --- a/in-cli/src/native_emit/uf2.rs +++ b/in-cli/src/native_emit/uf2.rs @@ -82,7 +82,7 @@ mod tests { use super::*; #[test] - fn encodes_single_block_with_family() { + fn encodes_single_block_with_family() -> Result<(), Box> { let payload = b"hello-thumb"; let bytes = encode_uf2( payload, @@ -94,46 +94,47 @@ mod tests { .expect("encode"); assert_eq!(bytes.len(), UF2_BLOCK_SIZE); assert_eq!( - u32::from_le_bytes(bytes[0..4].try_into().unwrap()), + u32::from_le_bytes(bytes[0..4].try_into()?), UF2_MAGIC_START0 ); assert_eq!( - u32::from_le_bytes(bytes[4..8].try_into().unwrap()), + u32::from_le_bytes(bytes[4..8].try_into()?), UF2_MAGIC_START1 ); assert_eq!( - u32::from_le_bytes(bytes[8..12].try_into().unwrap()) & UF2_FLAG_FAMILY_ID_PRESENT, + u32::from_le_bytes(bytes[8..12].try_into()?) & UF2_FLAG_FAMILY_ID_PRESENT, UF2_FLAG_FAMILY_ID_PRESENT ); assert_eq!( - u32::from_le_bytes(bytes[12..16].try_into().unwrap()), + u32::from_le_bytes(bytes[12..16].try_into()?), 0x1000_0000 ); assert_eq!( - u32::from_le_bytes(bytes[16..20].try_into().unwrap()), + u32::from_le_bytes(bytes[16..20].try_into()?), payload.len() as u32 ); assert_eq!(&bytes[32..32 + payload.len()], payload); assert_eq!( - u32::from_le_bytes(bytes[508..512].try_into().unwrap()), + u32::from_le_bytes(bytes[508..512].try_into()?), UF2_MAGIC_END ); + Ok(()) } #[test] - fn splits_large_payload() { + fn splits_large_payload() -> Result<(), Box> { let payload = vec![0xABu8; UF2_PAYLOAD_MAX + 10]; let bytes = encode_uf2(&payload, &Uf2Options::default()).expect("encode"); assert_eq!(bytes.len(), UF2_BLOCK_SIZE * 2); - assert_eq!(u32::from_le_bytes(bytes[24..28].try_into().unwrap()), 2); + assert_eq!(u32::from_le_bytes(bytes[24..28].try_into()?), 2); assert_eq!( u32::from_le_bytes( bytes[UF2_BLOCK_SIZE + 20..UF2_BLOCK_SIZE + 24] - .try_into() - .unwrap() + .try_into()? ), 1 ); + Ok(()) } #[test] From d9cebc58df801c45da2572d2b0b1c94a26d1328a Mon Sep 17 00:00:00 2001 From: undivisible <136312656+undivisible@users.noreply.github.com> Date: Thu, 10 Sep 2026 17:04:53 +0000 Subject: [PATCH 2/2] refactor(uf2): replace unwrap with ? in tests Updated test signatures in `in-cli/src/native_emit/uf2.rs` to return `Result<(), Box>` and replaced unsafe `unwrap()` calls on `try_into()` with the `?` operator. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- in-cli/src/native_emit/uf2.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/in-cli/src/native_emit/uf2.rs b/in-cli/src/native_emit/uf2.rs index 1bdae6f0..f3599fa4 100644 --- a/in-cli/src/native_emit/uf2.rs +++ b/in-cli/src/native_emit/uf2.rs @@ -105,10 +105,7 @@ mod tests { u32::from_le_bytes(bytes[8..12].try_into()?) & UF2_FLAG_FAMILY_ID_PRESENT, UF2_FLAG_FAMILY_ID_PRESENT ); - assert_eq!( - u32::from_le_bytes(bytes[12..16].try_into()?), - 0x1000_0000 - ); + assert_eq!(u32::from_le_bytes(bytes[12..16].try_into()?), 0x1000_0000); assert_eq!( u32::from_le_bytes(bytes[16..20].try_into()?), payload.len() as u32 @@ -128,10 +125,7 @@ mod tests { assert_eq!(bytes.len(), UF2_BLOCK_SIZE * 2); assert_eq!(u32::from_le_bytes(bytes[24..28].try_into()?), 2); assert_eq!( - u32::from_le_bytes( - bytes[UF2_BLOCK_SIZE + 20..UF2_BLOCK_SIZE + 24] - .try_into()? - ), + u32::from_le_bytes(bytes[UF2_BLOCK_SIZE + 20..UF2_BLOCK_SIZE + 24].try_into()?), 1 ); Ok(())