* [PATCH proxmox] resource-scheduling: topsis: add context to 'unwraps'
@ 2026-02-25 13:06 Dominik Rusovac
2026-02-25 15:08 ` Daniel Kral
0 siblings, 1 reply; 4+ messages in thread
From: Dominik Rusovac @ 2026-02-25 13:06 UTC (permalink / raw)
To: pve-devel
Adds context as to why particular 'unwraps' panic.
Signed-off-by: Dominik Rusovac <d.rusovac@proxmox.com>
---
proxmox-resource-scheduling/src/topsis.rs | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/proxmox-resource-scheduling/src/topsis.rs b/proxmox-resource-scheduling/src/topsis.rs
index 6d078aa6..25934f5b 100644
--- a/proxmox-resource-scheduling/src/topsis.rs
+++ b/proxmox-resource-scheduling/src/topsis.rs
@@ -145,8 +145,10 @@ impl<const N: usize> IdealAlternatives<N> {
let min = fixed_criterion
.clone()
.min_by(|a, b| a.total_cmp(b))
- .unwrap();
- let max = fixed_criterion.max_by(|a, b| a.total_cmp(b)).unwrap();
+ .expect("zero alternatives");
+ let max = fixed_criterion
+ .max_by(|a, b| a.total_cmp(b))
+ .expect("zero alternatives");
(best[n], worst[n]) = match criteria[n].maximize {
true => (max, min),
@@ -234,8 +236,7 @@ macro_rules! criteria_struct {
$(
$crate::topsis::Criterion::new($crit_name.to_string(), $crit_weight),
)*
- ])
- .unwrap()
+ ]).unwrap_or_else(|err| panic!("constructing criteria failed: {err}"))
});
impl From<$name> for [f64; $count_name] {
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH proxmox] resource-scheduling: topsis: add context to 'unwraps'
2026-02-25 13:06 [PATCH proxmox] resource-scheduling: topsis: add context to 'unwraps' Dominik Rusovac
@ 2026-02-25 15:08 ` Daniel Kral
2026-02-26 9:28 ` Dominik Rusovac
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Kral @ 2026-02-25 15:08 UTC (permalink / raw)
To: Dominik Rusovac, pve-devel
Thanks for the patch!
On Wed Feb 25, 2026 at 2:06 PM CET, Dominik Rusovac wrote:
> Adds context as to why particular 'unwraps' panic.
>
> Signed-off-by: Dominik Rusovac <d.rusovac@proxmox.com>
> ---
> proxmox-resource-scheduling/src/topsis.rs | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/proxmox-resource-scheduling/src/topsis.rs b/proxmox-resource-scheduling/src/topsis.rs
> index 6d078aa6..25934f5b 100644
> --- a/proxmox-resource-scheduling/src/topsis.rs
> +++ b/proxmox-resource-scheduling/src/topsis.rs
> @@ -145,8 +145,10 @@ impl<const N: usize> IdealAlternatives<N> {
> let min = fixed_criterion
> .clone()
> .min_by(|a, b| a.total_cmp(b))
> - .unwrap();
> - let max = fixed_criterion.max_by(|a, b| a.total_cmp(b)).unwrap();
> + .expect("zero alternatives");
> + let max = fixed_criterion
> + .max_by(|a, b| a.total_cmp(b))
> + .expect("zero alternatives");
Hm, it might make sense to fall back to sensible defaults here or return
a Result<> (as this is only used internally in score_alternatives(...))
and return either an empty vec there or an error as well.
>
> (best[n], worst[n]) = match criteria[n].maximize {
> true => (max, min),
> @@ -234,8 +236,7 @@ macro_rules! criteria_struct {
> $(
> $crate::topsis::Criterion::new($crit_name.to_string(), $crit_weight),
> )*
> - ])
> - .unwrap()
> + ]).unwrap_or_else(|err| panic!("constructing criteria failed: {err}"))
> });
>
> impl From<$name> for [f64; $count_name] {
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH proxmox] resource-scheduling: topsis: add context to 'unwraps'
2026-02-25 15:08 ` Daniel Kral
@ 2026-02-26 9:28 ` Dominik Rusovac
2026-02-26 10:18 ` Daniel Kral
0 siblings, 1 reply; 4+ messages in thread
From: Dominik Rusovac @ 2026-02-26 9:28 UTC (permalink / raw)
To: Daniel Kral, pve-devel
I agree, unwrapping the option is indeed questionable. Yet these unwraps
seemed good enough and I didn't want to touch the error handling itself,
as it would entail more changes. Atm, we have no designated Error types
to map to and imo just bail!-ing on a Result in this place adds no
reasonable value. Consistently propagating errors from start to end
would be more appropriate, I suppose.
For now, I just added some context as to what must have gone wrong in
this very situation, because it changes just a tiny bit of code, while
adding reasonable information.
I could send a v2 that touches error handling in general, though.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH proxmox] resource-scheduling: topsis: add context to 'unwraps'
2026-02-26 9:28 ` Dominik Rusovac
@ 2026-02-26 10:18 ` Daniel Kral
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Kral @ 2026-02-26 10:18 UTC (permalink / raw)
To: Dominik Rusovac, pve-devel
On Thu Feb 26, 2026 at 10:28 AM CET, Dominik Rusovac wrote:
> I agree, unwrapping the option is indeed questionable. Yet these unwraps
> seemed good enough and I didn't want to touch the error handling itself,
> as it would entail more changes. Atm, we have no designated Error types
> to map to and imo just bail!-ing on a Result in this place adds no
> reasonable value. Consistently propagating errors from start to end
> would be more appropriate, I suppose.
>
> For now, I just added some context as to what must have gone wrong in
> this very situation, because it changes just a tiny bit of code, while
> adding reasonable information.
>
> I could send a v2 that touches error handling in general, though.
Currently, the only user of score_alternatives(...) is
score_nodes_to_start_service(...), where it's enough that nodes is an
empty slice to cause a panic. This isn't a problem now because the
function is unlikely to be called as there's always at least one node
available.
If we're going to use these for the load balancer, it could be way
easier to run into this, e.g. there is only one service restricted to a
single node, i.e., no migration candidates. Of course we could catch
this early, but returning a generic Error here and then handling that in
score_alternatives(...) to return an empty vec would be an improvement.
Having error types would be plus here of course, but needs some
consideration that it doesn't break building packages that use this
crate.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-26 10:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-25 13:06 [PATCH proxmox] resource-scheduling: topsis: add context to 'unwraps' Dominik Rusovac
2026-02-25 15:08 ` Daniel Kral
2026-02-26 9:28 ` Dominik Rusovac
2026-02-26 10:18 ` Daniel Kral
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.