Error: Division by zero in baw_calc_ratio()

Created on 8 July 2025, 16 days ago

Problem/Motivation

Seeing this WSOD error just now…?

Message DivisionByZeroError: Division by zero in baw_calc_ratio() (line 42 of /home/mycpanel/public_html/rjcom2/web/modules/contrib/bawstats/modules/render_table.inc.php).
Severity Error
Hostname xxx
Operations
Backtrace

#0 /home/bisonble/public_html/rjcom2/web/modules/contrib/bawstats/modules/render_table.inc.php(172): baw_calc_ratio()
#1 /home/bisonble/public_html/rjcom2/web/modules/contrib/bawstats/engine/display.inc.php(600): baw_render_table()
#2 /home/bisonble/public_html/rjcom2/web/modules/contrib/bawstats/src/Controller/BawstatsController.php(210): baw_display_visitors()
#3 /home/bisonble/public_html/rjcom2/web/modules/contrib/bawstats/src/Controller/BawstatsController.php(70): Drupal\bawstats\Controller\BawstatsController->bawstatsDisplay()
#4 [internal function]: Drupal\bawstats\Controller\BawstatsController->viewStats()

Steps to reproduce

Not exactly sure…

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada bisonbleu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @bisonbleu
  • πŸ‡¬πŸ‡§United Kingdom egfrith

    Hmm... I'm wondering if there is a ratio stored like "0/0". In this case, I think the answer is to return 0. However, if we are trying to compute "1/0" that makes no sense, and we should at least return a meaningful error.

    The aim of the attached patch is to implement the above idea. If there's an error, there's some problem upstream in the code of this issue, which will need more thinking about.

    This patch works for me, in the sense that it doesn't break normal behaviour. However, I've not managed to reproduce the divide by zero error - I suspect it needs a particular set of data. If you could try running with this patch and test a year/month that (hopefully) reliably gave an error, we could maybe then see if it's just bad luck with the data (perhaps no visitors yet), or something more serious.

  • πŸ‡¨πŸ‡¦Canada bisonbleu

    Tested the patch. The View site statistics page now loads. But the charts for Days of month, Days of week (Averages), Hours (Averages) are back to displaying only 3 columns - i.e. broken.

Production build 0.71.5 2024