From 31ed93da3397941bc336e307fa7045b613bcc2fd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Mar 2026 23:09:23 +0000 Subject: [PATCH] Fix unsafe type assertion panic in metrics.go when status["total_size"] is nil Co-authored-by: kira1928 <2352900+kira1928@users.noreply.github.com> Agent-Logs-Url: https://github.com/bililive-go/bililive-go/sessions/e3b4acf7-a4ea-47c7-98c9-c51ca1cc43ee --- src/metrics/metrics.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/metrics/metrics.go b/src/metrics/metrics.go index f329cee..a7c5517 100644 --- a/src/metrics/metrics.go +++ b/src/metrics/metrics.go @@ -80,9 +80,11 @@ func (c collector) Collect(ch chan<- prometheus.Metric) { if r, err := c.inst.RecorderManager.(recorders.Manager).GetRecorder(context.Background(), id); err == nil { if status, err := r.GetStatus(); err == nil { - if value, err := strconv.ParseFloat(status["total_size"].(string), 64); err == nil { - ch <- prometheus.MustNewConstMetric(recorderTotalBytes, prometheus.CounterValue, value, - string(id), l.GetRawUrl(), info.HostName, info.RoomName) + if totalSize, ok := status["total_size"].(string); ok { + if value, err := strconv.ParseFloat(totalSize, 64); err == nil { + ch <- prometheus.MustNewConstMetric(recorderTotalBytes, prometheus.CounterValue, value, + string(id), l.GetRawUrl(), info.HostName, info.RoomName) + } } } }