aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2025-06-30 15:24:19 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2025-06-30 15:24:19 -0700
commita9c6485fb00dbf2e4b55351c1ae74d4eaca3eec9 (patch)
treeba58bfe00604b2231e4b8735b74d09e3e9ae48dc /internal
parent043e270a03f4ffff6d7115bd7ca5083a9eb80e46 (diff)
Replace inappropriate panic calls with proper error handling
- Convert panic in news article processing to return error instead - Replace panic in API stats endpoint with HTTP error response - Update ThreadedNewsMgr interface to return errors from ListArticles - Ensure server stability by handling errors gracefully
Diffstat (limited to 'internal')
-rw-r--r--internal/mobius/api.go3
-rw-r--r--internal/mobius/threaded_news.go2
-rw-r--r--internal/mobius/transaction_handlers.go5
3 files changed, 7 insertions, 3 deletions
diff --git a/internal/mobius/api.go b/internal/mobius/api.go
index 4dfc575..0a20d01 100644
--- a/internal/mobius/api.go
+++ b/internal/mobius/api.go
@@ -263,7 +263,8 @@ func (srv *APIServer) ReloadHandler(reloadFunc func()) func(w http.ResponseWrite
func (srv *APIServer) RenderStats(w http.ResponseWriter, _ *http.Request) {
u, err := json.Marshal(srv.hlServer.CurrentStats())
if err != nil {
- panic(err)
+ http.Error(w, "failed to marshal stats", http.StatusInternalServerError)
+ return
}
_, _ = w.Write(u)
diff --git a/internal/mobius/threaded_news.go b/internal/mobius/threaded_news.go
index e9d9c22..67e8282 100644
--- a/internal/mobius/threaded_news.go
+++ b/internal/mobius/threaded_news.go
@@ -195,7 +195,7 @@ func (n *ThreadedNewsYAML) DeleteArticle(newsPath []string, articleID uint32, _
return n.writeFile()
}
-func (n *ThreadedNewsYAML) ListArticles(newsPath []string) hotline.NewsArtListData {
+func (n *ThreadedNewsYAML) ListArticles(newsPath []string) (hotline.NewsArtListData, error) {
n.mu.Lock()
defer n.mu.Unlock()
diff --git a/internal/mobius/transaction_handlers.go b/internal/mobius/transaction_handlers.go
index d8c4cb5..5181e15 100644
--- a/internal/mobius/transaction_handlers.go
+++ b/internal/mobius/transaction_handlers.go
@@ -1319,7 +1319,10 @@ func HandleGetNewsArtNameList(cc *hotline.ClientConn, t *hotline.Transaction) (r
return res
}
- nald := cc.Server.ThreadedNewsMgr.ListArticles(pathStrs)
+ nald, err := cc.Server.ThreadedNewsMgr.ListArticles(pathStrs)
+ if err != nil {
+ return res
+ }
b, err := io.ReadAll(&nald)
if err != nil {