From 7274771cb4cdef8a8ddcabc1aa370797af28616d Mon Sep 17 00:00:00 2001 From: Pavan Kumar VH Date: Thu, 3 Sep 2026 12:34:46 +0530 Subject: [PATCH] Fix NaN handling in pct function in db-health-alerts The function didn't validate that part and whole are finite numbers. If either was NaN or Infinity, Math.round((part / whole) * 100) would return NaN. Added Number.isFinite() checks to return 0 for invalid numbers. --- common/src/util/db-health-alerts.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/util/db-health-alerts.ts b/common/src/util/db-health-alerts.ts index 0c88fda3bc..451713e2ea 100644 --- a/common/src/util/db-health-alerts.ts +++ b/common/src/util/db-health-alerts.ts @@ -292,8 +292,10 @@ export function evaluateStatCoverage(row: StatCoverageRow): StatCoverage { // may break the alert that does not consult it. const statementsBlind = statementRows === 0 const activityBlind = activityVisible === 0 - const pct = (part: number, whole: number) => - whole > 0 ? Math.round((part / whole) * 100) : 0 + const pct = (part: number, whole: number) => { + if (!Number.isFinite(part) || !Number.isFinite(whole) || whole <= 0) return 0 + return Math.round((part / whole) * 100) + } const summary = row.has_read_all_stats ? `role ${row.role} has pg_read_all_stats: full fleet visibility` : `role ${row.role} lacks pg_read_all_stats — ${statementsWithText}/${statementRows} ` +