diff --git a/rust/agama-lib/src/dbus.rs b/rust/agama-lib/src/dbus.rs index b814f614b6..50383f7b6b 100644 --- a/rust/agama-lib/src/dbus.rs +++ b/rust/agama-lib/src/dbus.rs @@ -29,6 +29,8 @@ where T::try_from(value).map_err(|e| e.into()) } +/// It is similar helper like get_property with difference that name does not need to be in HashMap. +/// In such case `None``is returned, so type has to be enclosed in `Option`.` pub fn get_optional_property<'a, T>( properties: &'a HashMap, name: &str, diff --git a/rust/agama-lib/src/error.rs b/rust/agama-lib/src/error.rs index 5ef274afe3..30f61af834 100644 --- a/rust/agama-lib/src/error.rs +++ b/rust/agama-lib/src/error.rs @@ -10,6 +10,8 @@ pub enum ServiceError { DBus(#[from] zbus::Error), #[error("Could not connect to Agama bus at '{0}': {1}")] DBusConnectionError(String, #[source] zbus::Error), + #[error("D-Bus protocol error: {0}")] + DBusProtocol(#[from] zbus::fdo::Error), #[error("Unexpected type on D-Bus '{0}'")] ZVariant(#[from] zvariant::Error), // it's fine to say only "Error" because the original diff --git a/rust/agama-lib/src/storage/client.rs b/rust/agama-lib/src/storage/client.rs index 3c49b2866c..3828c02720 100644 --- a/rust/agama-lib/src/storage/client.rs +++ b/rust/agama-lib/src/storage/client.rs @@ -32,6 +32,7 @@ pub struct Action { } /// Represents value for target key of Volume +/// It is snake cased when serializing to be compatible with yast2-storage-ng. #[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] #[serde(rename_all = "snake_case")] pub enum VolumeTarget { @@ -286,7 +287,7 @@ impl<'a> StorageClient<'a> { ) -> Result { let interfaces = &object.1; Ok(Device { - device_info: self.build_device_info(interfaces).await?, + device_info: self.build_device_info(object).await?, component: None, drive: None, block_device: self.build_block_device(interfaces).await?, @@ -302,11 +303,7 @@ impl<'a> StorageClient<'a> { } pub async fn system_devices(&self) -> Result, ServiceError> { - let objects = self - .object_manager_proxy - .get_managed_objects() - .await - .context("Failed to get managed objects")?; + let objects = self.object_manager_proxy.get_managed_objects().await?; let mut result = vec![]; for object in objects { let path = &object.0; @@ -321,11 +318,7 @@ impl<'a> StorageClient<'a> { } pub async fn staging_devices(&self) -> Result, ServiceError> { - let objects = self - .object_manager_proxy - .get_managed_objects() - .await - .context("Failed to get managed objects")?; + let objects = self.object_manager_proxy.get_managed_objects().await?; let mut result = vec![]; for object in objects { let path = &object.0; @@ -341,8 +334,12 @@ impl<'a> StorageClient<'a> { async fn build_device_info( &self, - interfaces: &HashMap>, + object: &( + OwnedObjectPath, + HashMap>, + ), ) -> Result { + let interfaces = &object.1; let interface: OwnedInterfaceName = InterfaceName::from_static_str_unchecked("org.opensuse.Agama.Storage1.Device").into(); let properties = interfaces.get(&interface); @@ -354,9 +351,9 @@ impl<'a> StorageClient<'a> { description: get_property(properties, "Description")?, }) } else { - Err(ServiceError::Anyhow(anyhow!( - "Device does not implement device info" - ))) + let message = + format!("storage device {} is missing Device interface", object.0).to_string(); + Err(zbus::zvariant::Error::Message(message).into()) } }