From 1906baa35c41331bca44d9e9bfbcfefb8280688b Mon Sep 17 00:00:00 2001 From: Dean Roehrich Date: Fri, 7 Jun 2024 11:50:51 -0500 Subject: [PATCH] Handle empty capacity when a drive cannot be found. Avoid doing a divide-by-zero and panicing the process. Signed-off-by: Dean Roehrich --- pkg/manager-nvme/manager.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/manager-nvme/manager.go b/pkg/manager-nvme/manager.go index b31cd6c..0ab72ce 100644 --- a/pkg/manager-nvme/manager.go +++ b/pkg/manager-nvme/manager.go @@ -1137,7 +1137,12 @@ func (mgr *Manager) StorageIdStoragePoolsStoragePoolIdGet(storageId, storagePool }, } - model.RemainingCapacityPercent = int64(float64(s.unallocatedBytes/s.capacityBytes) * 100.0) + if s.capacityBytes == 0 { + // If a drive could not be found, don't divide by zero. + model.RemainingCapacityPercent = 0 + } else { + model.RemainingCapacityPercent = int64(float64(s.unallocatedBytes/s.capacityBytes) * 100.0) + } return nil }