]> git.proxmox.com Git - pve-installer.git/commitdiff
tui: add better error handling to BootdiskOptions::get_values()
authorChristoph Heiss <c.heiss@proxmox.com>
Tue, 20 Jun 2023 08:22:41 +0000 (10:22 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 20 Jun 2023 09:09:39 +0000 (11:09 +0200)
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
proxmox-tui-installer/src/main.rs
proxmox-tui-installer/src/views/bootdisk.rs

index 9df781669f985022239125937ebc0e3143503426..0588f9fd7d8e87cd8109da856fd2a6c7f9d995c1 100644 (file)
@@ -352,18 +352,19 @@ fn bootdisk_dialog(siv: &mut Cursive) -> InstallerView {
         BootdiskOptionsView::new(&state.runtime_info.disks, &state.options.bootdisk)
             .with_name("bootdisk-options"),
         Box::new(|siv| {
-            let options = siv
-                .call_on_name("bootdisk-options", BootdiskOptionsView::get_values)
-                .flatten();
-
-            if let Some(options) = options {
-                siv.with_user_data(|state: &mut InstallerState| {
-                    state.options.bootdisk = options;
-                });
-
-                switch_to_next_screen(siv, InstallerStep::Timezone, &timezone_dialog);
-            } else {
-                siv.add_layer(Dialog::info("Invalid values"));
+            let options = siv.call_on_name("bootdisk-options", BootdiskOptionsView::get_values);
+
+            match options {
+                Some(Ok(options)) => {
+                    siv.with_user_data(|state: &mut InstallerState| {
+                        state.options.bootdisk = options;
+                    });
+
+                    switch_to_next_screen(siv, InstallerStep::Timezone, &timezone_dialog);
+                }
+
+                Some(Err(err)) => siv.add_layer(Dialog::info(format!("Invalid values: {err}"))),
+                _ => siv.add_layer(Dialog::info("Invalid values")),
             }
         }),
     )
index f7dfaa91b4eedf76b9d17464ff19f3eac8df0393..aab71f1b68100fbd28f90fec606d8c64c403a7ee 100644 (file)
@@ -52,21 +52,22 @@ impl BootdiskOptionsView {
         }
     }
 
-    pub fn get_values(&mut self) -> Option<BootdiskOptions> {
+    pub fn get_values(&mut self) -> Result<BootdiskOptions, String> {
         let mut options = (*self.advanced_options).clone().into_inner();
 
         if [FsType::Ext4, FsType::Xfs].contains(&options.fstype) {
             let disk = self
                 .view
-                .get_child_mut(0)?
-                .downcast_mut::<NamedView<FormView>>()?
-                .get_mut()
-                .get_value::<SelectView<Disk>, _>(0)?;
+                .get_child_mut(0)
+                .and_then(|v| v.downcast_mut::<NamedView<FormView>>())
+                .map(NamedView::<FormView>::get_mut)
+                .and_then(|v| v.get_value::<SelectView<Disk>, _>(0))
+                .ok_or("failed to retrieve filesystem type")?;
 
             options.disks = vec![disk];
         }
 
-        Some(options)
+        Ok(options)
     }
 }