Average Watch Time: Infinity — JavaScript Bug Hunt
Inspired by every analytics dashboard that has proudly displayed "Infinity minutes" or "NaN%" on launch day, before any traffic arrived.
- Language: JavaScript
- Layer: Frontend
- Difficulty: Easy
- Concepts: Math, Division
- Modelled on: Analytics dashboards
- Visible tests: zero viewers is zero average; real traffic computes normally
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-3
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- zero viewers is zero average — expected 0 but got null
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by every analytics dashboard that has proudly displayed "Infinity minutes" or "NaN%" on launch day, before any traffic arrived. Division needs a denominator.
metrics.js computes the overview cards.
Bug report
BUG-INF · Reported by: dashboards
- avgWatchMs(totalMs, viewers): 0 viewers -> 0
- clickRate(clicks, views): percentage with ONE decimal; 0 views -> 0
Observed: fresh channels show "Infinity" and "NaN%" cards.
Logs
[cards] avg watch: Infinity min · CTR: NaN%The code as shipped
src/stats/metrics.js (editable)
// Overview card metrics.
exports.avgWatchMs = function (totalMs, viewers) {
return Math.round(totalMs / viewers);
};
exports.clickRate = function (clicks, views) {
return Math.round((clicks / views) * 1000) / 10;
};
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.