From 482db0b763f18b4aa8d227ff6acc862e8a597a77 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Fri, 24 Oct 2025 19:27:43 -0700 Subject: [PATCH] fix(media-loader): eliminate usage of unwrap and swap to result --- src/utils/media_loader.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/media_loader.rs b/src/utils/media_loader.rs index d8840ac..f3f4954 100644 --- a/src/utils/media_loader.rs +++ b/src/utils/media_loader.rs @@ -97,7 +97,7 @@ impl MediaLoaderHandle { } /// Creates a new device path for the media loader based on a vendor `guid`. - fn device_path(guid: Guid) -> Box { + fn device_path(guid: Guid) -> Result> { // The buffer for the device path. let mut path = Vec::new(); // Build a device path for the media loader with a vendor-specific guid. @@ -106,18 +106,18 @@ impl MediaLoaderHandle { vendor_guid: guid, vendor_defined_data: &[], }) - .unwrap() // We know that the device path is valid, so we can unwrap. + .context("unable to produce device path")? .finalize() - .unwrap(); // We know that the device path is valid, so we can unwrap. + .context("unable to produce device path")?; // Convert the device path to a boxed device path. // This is safer than dealing with a pooled device path. - path.to_boxed() + Ok(path.to_boxed()) } /// Checks if the media loader is already registered with the UEFI stack. fn already_registered(guid: Guid) -> Result { // Acquire the device path for the media loader. - let path = Self::device_path(guid); + let path = Self::device_path(guid)?; let mut existing_path = path.as_ref(); @@ -142,7 +142,7 @@ impl MediaLoaderHandle { /// to load the data from. pub fn register(guid: Guid, data: Box<[u8]>) -> Result { // Acquire the vendor device path for the media loader. - let path = Self::device_path(guid); + let path = Self::device_path(guid)?; // Check if the media loader is already registered. // If it is, we can't register it again safely.