[pve-devel] [PATCH pve-installer v3 6/7] tui: change get_value return type for easier error handling

Michael Köppl m.koeppl at proxmox.com
Thu Jun 26 17:11:17 CEST 2025


Adapt the return type of CidrAddressEditView's get_value implementation
for the FormViewGetValue trait to handle errors in case of invalid CIDR
similarly to other (parsing) errors done in the TUIs network dialog.

Signed-off-by: Michael Köppl <m.koeppl at proxmox.com>
---
 proxmox-tui-installer/src/main.rs      | 8 +++++---
 proxmox-tui-installer/src/views/mod.rs | 8 ++++----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 57a334f..15ee5d3 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -20,9 +20,8 @@ use proxmox_installer_common::{
     ROOT_PASSWORD_MIN_LENGTH,
     options::{BootdiskOptions, NetworkOptions, TimezoneOptions, email_validate},
     setup::{LocaleInfo, ProxmoxProduct, RuntimeInfo, SetupInfo, installer_setup},
-    utils::Fqdn,
+    utils::{CidrAddress, Fqdn},
 };
-
 mod setup;
 
 mod system;
@@ -536,7 +535,10 @@ fn network_dialog(siv: &mut Cursive) -> InstallerView {
 
                 let address = view
                     .get_value::<CidrAddressEditView, _>(2)
-                    .ok_or("failed to retrieve host address")?;
+                    .ok_or("failed to retrieve host address".to_string())
+                    .and_then(|(ip_addr, mask)| {
+                        CidrAddress::new(ip_addr, mask).map_err(|err| err.to_string())
+                    })?;
 
                 let gateway = view
                     .get_value::<EditView, _>(3)
diff --git a/proxmox-tui-installer/src/views/mod.rs b/proxmox-tui-installer/src/views/mod.rs
index 4364489..3211c93 100644
--- a/proxmox-tui-installer/src/views/mod.rs
+++ b/proxmox-tui-installer/src/views/mod.rs
@@ -387,8 +387,8 @@ where
     }
 }
 
-impl FormViewGetValue<CidrAddress> for CidrAddressEditView {
-    fn get_value(&self) -> Option<CidrAddress> {
+impl FormViewGetValue<(IpAddr, usize)> for CidrAddressEditView {
+    fn get_value(&self) -> Option<(IpAddr, usize)> {
         self.get_values()
     }
 }
@@ -569,7 +569,7 @@ impl CidrAddressEditView {
             .fixed_width(4)
     }
 
-    fn get_values(&self) -> Option<CidrAddress> {
+    fn get_values(&self) -> Option<(IpAddr, usize)> {
         let addr = self
             .view
             .get_child(0)?
@@ -587,7 +587,7 @@ impl CidrAddressEditView {
             .get_content()
             .ok()?;
 
-        CidrAddress::new(addr, mask).ok()
+        Some((addr, mask))
     }
 }
 
-- 
2.39.5





More information about the pve-devel mailing list