From daf767fa1e449e24d239ae980706a395967b2158 Mon Sep 17 00:00:00 2001 From: Louis Brauer Date: Fri, 19 Feb 2021 13:17:12 +0100 Subject: [PATCH] handle frequent panics from goradios --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index 7fb5928..a46e807 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ package main import ( + "fmt" "io" "log" "strings" @@ -52,6 +53,12 @@ var ( } ) +func handlePanic() { + if r := recover(); r != nil { + fmt.Println("Recovering from panic:", r) + } +} + func loadData(refresh bool) { cacheName := "cache" cache := gobcache.NewCache(gobcache.Config{}) @@ -70,6 +77,7 @@ func loadData(refresh bool) { data.Stations = goradios.FetchAllStationsDetailed(goradios.StationsOrderName, false, 0, 0, true) go func() { + defer handlePanic() for { log.Println("... top 5 stations with refresh every minute") data.Top5Stations = goradios.FetchAllStationsDetailed(goradios.StationsOrderLastCheckTime, true, 0, 5, true) -- 2.34.2