Skip to content

Commit 72c9ca7

Browse files
committed
fix(worker): guard average-time print on compute_time list, not analytics_line_count
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.
1 parent bb688fb commit 72c9ca7

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/tasks.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,18 @@ def read_analytics_file(package_status_id, package_id, link, session):
433433
# package_is_partial from the SQLite to know which screens to
434434
# render as N/A. Asking the user to re-export would mean a
435435
# ~30-day round-trip, so degrading gracefully is the kinder UX.
436-
if analytics_line_count > 0:
436+
# Guard on compute_time_per_line, NOT analytics_line_count: the
437+
# latter is bumped at the top of the loop, before the
438+
# `if not 'event_type' in analytics_line_json: continue` skip.
439+
# A file whose lines all lack event_type (Discord ships these
440+
# for some kinds of partial exports) would have line count > 0
441+
# but produce no usable events, which is the actual condition
442+
# for "we have nothing to average and nothing to chart".
443+
if compute_time_per_line:
437444
is_partial = False
438445
print(f'Average compute time per line: {sum(compute_time_per_line) / len(compute_time_per_line)}')
439446
else:
440-
print('Analytics file is empty — keeping is_partial=True; activity-driven stats will be N/A on the client.')
447+
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.')
441448

442449
print(f'Analytics data: {time.time() - start}')
443450
print(f'Session logs: {len(session_logs)}')

0 commit comments

Comments
 (0)