From 994c4ff0a71e4bd3d7236edf5701ba5f10434299 Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Tue, 20 Jun 2023 10:22:41 +0200 Subject: [PATCH] tui: add better error handling to BootdiskOptions::get_values() Signed-off-by: Christoph Heiss --- proxmox-tui-installer/src/main.rs | 21 +++++++++++---------- proxmox-tui-installer/src/views/bootdisk.rs | 13 +++++++------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs index 9df7816..0588f9f 100644 --- a/proxmox-tui-installer/src/main.rs +++ b/proxmox-tui-installer/src/main.rs @@ -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(); + let options = siv.call_on_name("bootdisk-options", BootdiskOptionsView::get_values); - if let Some(options) = options { - siv.with_user_data(|state: &mut InstallerState| { - state.options.bootdisk = options; - }); + 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); - } else { - siv.add_layer(Dialog::info("Invalid values")); + 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")), } }), ) diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs index f7dfaa9..aab71f1 100644 --- a/proxmox-tui-installer/src/views/bootdisk.rs +++ b/proxmox-tui-installer/src/views/bootdisk.rs @@ -52,21 +52,22 @@ impl BootdiskOptionsView { } } - pub fn get_values(&mut self) -> Option { + pub fn get_values(&mut self) -> Result { 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::>()? - .get_mut() - .get_value::, _>(0)?; + .get_child_mut(0) + .and_then(|v| v.downcast_mut::>()) + .map(NamedView::::get_mut) + .and_then(|v| v.get_value::, _>(0)) + .ok_or("failed to retrieve filesystem type")?; options.disks = vec![disk]; } - Some(options) + Ok(options) } }