Skip to content

Commit 3303505

Browse files
jonradoffclaude
andcommitted
Fix nil slice serialization in telemetry KPIs causing frontend crash
Go nil slices serialize to JSON null instead of []. The frontend crashed calling .length on null for mrrTrend, planDistribution, and other array fields. Initialize all slices as empty instead of nil. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7356a00 commit 3303505

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

backend/internal/telemetry/service.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ func (s *Service) CustomEventSummary(ctx context.Context, start, end time.Time,
482482
}
483483
defer cursor.Close(ctx)
484484

485-
var trend []DailyPoint
485+
trend := []DailyPoint{}
486486
for cursor.Next(ctx) {
487487
var result struct {
488488
Date string `bson:"_id"`
@@ -666,7 +666,7 @@ func (s *Service) weeklyActiveUsers(ctx context.Context, userIDs []primitive.Obj
666666
}
667667
defer cursor.Close(ctx)
668668

669-
var points []DailyPoint
669+
points := []DailyPoint{}
670670
for cursor.Next(ctx) {
671671
var result struct {
672672
ID struct {
@@ -713,7 +713,7 @@ func (s *Service) monthlyActiveUsers(ctx context.Context, userIDs []primitive.Ob
713713
}
714714
defer cursor.Close(ctx)
715715

716-
var points []DailyPoint
716+
points := []DailyPoint{}
717717
for cursor.Next(ctx) {
718718
var result struct {
719719
ID struct {
@@ -750,7 +750,7 @@ func (s *Service) topCustomEvents(ctx context.Context, start, end time.Time, lim
750750
}
751751
defer cursor.Close(ctx)
752752

753-
var features []FeatureUse
753+
features := []FeatureUse{}
754754
for cursor.Next(ctx) {
755755
var result struct {
756756
Name string `bson:"_id"`
@@ -780,7 +780,7 @@ func (s *Service) creditConsumptionTrend(ctx context.Context, start, end time.Ti
780780
}
781781
defer cursor.Close(ctx)
782782

783-
var points []DailyPoint
783+
points := []DailyPoint{}
784784
for cursor.Next(ctx) {
785785
var result struct {
786786
Date string `bson:"_id"`
@@ -940,7 +940,7 @@ func (s *Service) planDistribution(ctx context.Context) []PlanShare {
940940
}
941941
defer cursor.Close(ctx)
942942

943-
var shares []PlanShare
943+
shares := []PlanShare{}
944944
var total int64
945945
for cursor.Next(ctx) {
946946
var result struct {
@@ -980,7 +980,7 @@ func (s *Service) mrrTrend(ctx context.Context, start, end time.Time) []DailyPoi
980980
}
981981
defer cursor.Close(ctx)
982982

983-
var points []DailyPoint
983+
points := []DailyPoint{}
984984
for cursor.Next(ctx) {
985985
var m models.DailyMetric
986986
if cursor.Decode(&m) == nil {
@@ -1010,7 +1010,7 @@ func (s *Service) subscriberTrend(ctx context.Context, start, end time.Time) []D
10101010
}
10111011
defer cursor.Close(ctx)
10121012

1013-
var points []DailyPoint
1013+
points := []DailyPoint{}
10141014
for cursor.Next(ctx) {
10151015
var result struct {
10161016
Date string `bson:"_id"`
@@ -1030,7 +1030,7 @@ func (s *Service) aggregateDailyPoints(ctx context.Context, pipeline mongo.Pipel
10301030
}
10311031
defer cursor.Close(ctx)
10321032

1033-
var points []DailyPoint
1033+
points := []DailyPoint{}
10341034
for cursor.Next(ctx) {
10351035
var result struct {
10361036
Date string `bson:"_id"`

0 commit comments

Comments
 (0)