Skip to content

Commit 7274771

Browse files
committed
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.
1 parent 7b65652 commit 7274771

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

common/src/util/db-health-alerts.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,10 @@ export function evaluateStatCoverage(row: StatCoverageRow): StatCoverage {
292292
// may break the alert that does not consult it.
293293
const statementsBlind = statementRows === 0
294294
const activityBlind = activityVisible === 0
295-
const pct = (part: number, whole: number) =>
296-
whole > 0 ? Math.round((part / whole) * 100) : 0
295+
const pct = (part: number, whole: number) => {
296+
if (!Number.isFinite(part) || !Number.isFinite(whole) || whole <= 0) return 0
297+
return Math.round((part / whole) * 100)
298+
}
297299
const summary = row.has_read_all_stats
298300
? `role ${row.role} has pg_read_all_stats: full fleet visibility`
299301
: `role ${row.role} lacks pg_read_all_stats — ${statementsWithText}/${statementRows} ` +

0 commit comments

Comments
 (0)