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 <[email protected]>
> ---
> 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] {