[pve-devel] [PATCH installer v4 6/8] tui: change get_value return type for easier error handling
Michael Köppl
m.koeppl at proxmox.com
Fri Jul 11 18:27:09 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 | 9 +++++----
2 files changed, 10 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..537e3ed 100644
--- a/proxmox-tui-installer/src/views/mod.rs
+++ b/proxmox-tui-installer/src/views/mod.rs
@@ -387,8 +387,9 @@ where
}
}
-impl FormViewGetValue<CidrAddress> for CidrAddressEditView {
- fn get_value(&self) -> Option<CidrAddress> {
+impl FormViewGetValue<(IpAddr, usize)> for CidrAddressEditView {
+ // FIXME: return CidrAddress (again) with proper error handling through Result
+ fn get_value(&self) -> Option<(IpAddr, usize)> {
self.get_values()
}
}
@@ -569,7 +570,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 +588,7 @@ impl CidrAddressEditView {
.get_content()
.ok()?;
- CidrAddress::new(addr, mask).ok()
+ Some((addr, mask))
}
}
--
2.47.2
More information about the pve-devel
mailing list