From c1738620e33105a2622588561c8f3d1d69735678 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 3 Nov 2023 08:12:36 -0500 Subject: [PATCH] remove unwraps in registry_query command (#10936) # Description After talking to @CAD97, I decided to change these unwraps to expects. See the comments. The bigger question is, how did unwrap pass the CI? # User-Facing Changes # Tests + Formatting # After Submitting --- .../nu-command/src/system/registry_query.rs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/crates/nu-command/src/system/registry_query.rs b/crates/nu-command/src/system/registry_query.rs index 5cb5f9d29d..90bc14bb15 100644 --- a/crates/nu-command/src/system/registry_query.rs +++ b/crates/nu-command/src/system/registry_query.rs @@ -308,16 +308,21 @@ fn reg_value_to_nu_list_string(reg_value: winreg::RegValue, call_span: Span) -> } fn reg_value_to_nu_int(reg_value: winreg::RegValue, call_span: Span) -> nu_protocol::Value { - let value = match reg_value.vtype { - REG_DWORD => u32::from_reg_value(®_value).unwrap() as i64, - REG_DWORD_BIG_ENDIAN => { - // winreg (v0.51.0) doesn't natively decode REG_DWORD_BIG_ENDIAN - u32::from_be_bytes(unsafe { *reg_value.bytes.as_ptr().cast() }) as i64 - } - REG_QWORD => u64::from_reg_value(®_value).unwrap() as i64, - _ => unreachable!( - "registry value type should be REG_DWORD, REG_DWORD_BIG_ENDIAN, or REG_QWORD" - ), - }; + let value = + match reg_value.vtype { + // See discussion here https://github.com/nushell/nushell/pull/10806#issuecomment-1791832088 + // "The unwraps here are effectively infallible...", so I changed them to expects. + REG_DWORD => u32::from_reg_value(®_value) + .expect("registry value type should be REG_DWORD") as i64, + REG_DWORD_BIG_ENDIAN => { + // winreg (v0.51.0) doesn't natively decode REG_DWORD_BIG_ENDIAN + u32::from_be_bytes(unsafe { *reg_value.bytes.as_ptr().cast() }) as i64 + } + REG_QWORD => u64::from_reg_value(®_value) + .expect("registry value type should be REG_QWORD") as i64, + _ => unreachable!( + "registry value type should be REG_DWORD, REG_DWORD_BIG_ENDIAN, or REG_QWORD" + ), + }; Value::int(value, call_span) }