From 5182dd7742bd78654dfb862636ca31c36f78ab07 Mon Sep 17 00:00:00 2001 From: Nestor Fleitas Date: Thu, 30 Jul 2026 01:01:53 -0300 Subject: [PATCH] fix(web): add missing returns after http.Error in handlers Five handlers wrote an error response but continued executing: - handleService: an invalid JSON body returned 400 but still invoked service.CallService with a zero-value WebCallType - handleService: a response-marshal failure still wrote headers/body on top of the 500 - handleWaveFile: an invalid offset returned 400 but kept serving the file with offset=0 - handleWaveFile: a fileinfo-marshal failure still streamed the file data after the 500 - handleStreamFile: an ExpandHomeDir error returned 400 but still called http.ServeFile with the unexpanded path Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01NctL6NKspWCzRxHJDwBGMk --- pkg/web/web.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/web/web.go b/pkg/web/web.go index 106db981e4..03ecab1a51 100644 --- a/pkg/web/web.go +++ b/pkg/web/web.go @@ -119,12 +119,14 @@ func handleService(w http.ResponseWriter, r *http.Request) { err = json.Unmarshal(bodyData, &webCall) if err != nil { http.Error(w, fmt.Sprintf("invalid request body: %v", err), http.StatusBadRequest) + return } rtn := service.CallService(r.Context(), webCall) jsonRtn, err := json.Marshal(rtn) if err != nil { http.Error(w, fmt.Sprintf("error serializing response: %v", err), http.StatusInternalServerError) + return } w.Header().Set(ContentTypeHeaderKey, ContentTypeJson) w.Header().Set(ContentLengthHeaderKey, fmt.Sprintf("%d", len(jsonRtn))) @@ -157,6 +159,7 @@ func handleWaveFile(w http.ResponseWriter, r *http.Request) { offset, err = strconv.ParseInt(offsetStr, 10, 64) if err != nil { http.Error(w, fmt.Sprintf("invalid offset: %v", err), http.StatusBadRequest) + return } } if _, err := uuid.Parse(zoneId); err != nil { @@ -180,6 +183,7 @@ func handleWaveFile(w http.ResponseWriter, r *http.Request) { jsonFileBArr, err := json.Marshal(file) if err != nil { http.Error(w, fmt.Sprintf("error serializing file info: %v", err), http.StatusInternalServerError) + return } // can make more efficient by checking modtime + If-Modified-Since headers to allow caching dataStartIdx := file.DataStartIdx() @@ -239,6 +243,7 @@ func handleLocalStreamFile(w http.ResponseWriter, r *http.Request, path string, path, err := wavebase.ExpandHomeDir(path) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) + return } http.ServeFile(w, r, path) }