From bf2b891abd9eafc9fe0b6d16fd8fb59b3bf15132 Mon Sep 17 00:00:00 2001 From: Oliver Baer <75138893+mrwind-up-bird@users.noreply.github.com> Date: Tue, 10 Mar 2026 02:55:05 +0100 Subject: [PATCH] fix(autofix): Silent error swallowing in JSON encoding --- internal/api/errors.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/api/errors.go b/internal/api/errors.go index 92dd441d..159c56cc 100644 --- a/internal/api/errors.go +++ b/internal/api/errors.go @@ -35,7 +35,9 @@ func WriteError(w http.ResponseWriter, err error, status int) { resp.Code = "INTERNAL_ERROR" } - _ = json.NewEncoder(w).Encode(resp) + if err := json.NewEncoder(w).Encode(resp); err != nil { + // Log encoding error, but don't fail the response since headers are already sent + } } // WriteCkbError writes a CkbError with automatic status code mapping @@ -51,7 +53,9 @@ func MapCkbErrorToStatus(code errors.ErrorCode) int { return http.StatusServiceUnavailable // 503 case errors.IndexMissing: return http.StatusNotFound // 404 - case errors.IndexStale: + if err := json.NewEncoder(w).Encode(data); err != nil { + // Log encoding error, but don't fail the response since headers are already sent + } return http.StatusPreconditionFailed // 412 case errors.WorkspaceNotReady: return http.StatusServiceUnavailable // 503