From 72c9ca7a3cca836935ad959b620215fa5cf748b3 Mon Sep 17 00:00:00 2001 From: Androz2091 Date: Mon, 4 May 2026 01:27:39 -0700 Subject: [PATCH] fix(worker): guard average-time print on compute_time list, not analytics_line_count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #81 used analytics_line_count > 0 as the divide-by-zero guard, but that variable is incremented at the top of the analytics loop — before the 'if not event_type: continue' skip. So a file whose lines all lack event_type (Discord apparently ships these for some kinds of partial exports) re-hit the same ZeroDivisionError surfaced as UNKNOWN_ERROR for package 14be73071701467d3aae144ab2e72f86. The actual condition for 'we have nothing to average' is that compute_time_per_line is empty. Guard on it directly. Behavior is identical for the two clean cases (empty file, fully-populated file) and additionally handles the lines-without-event_type case gracefully — is_partial stays True, no stats produced, no crash. --- src/tasks.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/tasks.py b/src/tasks.py index a200b47..798b7e1 100644 --- a/src/tasks.py +++ b/src/tasks.py @@ -433,11 +433,18 @@ def read_analytics_file(package_status_id, package_id, link, session): # package_is_partial from the SQLite to know which screens to # render as N/A. Asking the user to re-export would mean a # ~30-day round-trip, so degrading gracefully is the kinder UX. - if analytics_line_count > 0: + # Guard on compute_time_per_line, NOT analytics_line_count: the + # latter is bumped at the top of the loop, before the + # `if not 'event_type' in analytics_line_json: continue` skip. + # A file whose lines all lack event_type (Discord ships these + # for some kinds of partial exports) would have line count > 0 + # but produce no usable events, which is the actual condition + # for "we have nothing to average and nothing to chart". + if compute_time_per_line: is_partial = False print(f'Average compute time per line: {sum(compute_time_per_line) / len(compute_time_per_line)}') else: - print('Analytics file is empty — keeping is_partial=True; activity-driven stats will be N/A on the client.') + print(f'Analytics file produced no usable events ({analytics_line_count} raw lines) — keeping is_partial=True; activity-driven stats will be N/A on the client.') print(f'Analytics data: {time.time() - start}') print(f'Session logs: {len(session_logs)}')