From c51d1c8c26db76a02eac7b2ab2c8b1c4cec38303 Mon Sep 17 00:00:00 2001 From: Deluan Date: Sun, 28 Dec 2025 13:45:57 -0500 Subject: [PATCH] refactor(plugins): streamline error handling and improve plugin retrieval logic Signed-off-by: Deluan --- server/nativeapi/plugin.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/nativeapi/plugin.go b/server/nativeapi/plugin.go index 94615fdf7..66f2fddeb 100644 --- a/server/nativeapi/plugin.go +++ b/server/nativeapi/plugin.go @@ -53,8 +53,7 @@ func (api *Router) updatePlugin(w http.ResponseWriter, r *http.Request) { repo := api.ds.Plugin(ctx) // Get existing plugin to verify it exists - plugin, err := repo.Get(id) - if err != nil { + if _, err := repo.Get(id); err != nil { if errors.Is(err, rest.ErrPermissionDenied) { http.Error(w, "Access denied: admin privileges required", http.StatusForbidden) return @@ -96,7 +95,12 @@ func (api *Router) updatePlugin(w http.ResponseWriter, r *http.Request) { if err := api.pluginManager.EnablePlugin(ctx, id); err != nil { log.Error(ctx, "Error enabling plugin", "id", id, err) // Refresh plugin from DB to get the error - plugin, _ = repo.Get(id) + plugin, err := repo.Get(id) + if err != nil { + log.Error(ctx, "Error getting updated plugin after enable failure", "id", id, err) + http.Error(w, "Internal server error", http.StatusInternalServerError) + return + } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusUnprocessableEntity) _ = json.NewEncoder(w).Encode(plugin) @@ -112,7 +116,7 @@ func (api *Router) updatePlugin(w http.ResponseWriter, r *http.Request) { } // Refresh and return updated plugin - plugin, err = repo.Get(id) + plugin, err := repo.Get(id) if err != nil { log.Error(ctx, "Error getting updated plugin", "id", id, err) http.Error(w, "Internal server error", http.StatusInternalServerError)