From ac38f5f751b4f19cda85bb686fb4eebe4facb88f Mon Sep 17 00:00:00 2001 From: Arya Khochare <91268931+Aryakoste@users.noreply.github.com> Date: Wed, 9 Oct 2024 22:13:34 +0530 Subject: [PATCH] Errcheck issues fixed in server/channels/api4/brand.go (#28362) * errcheck proper error handling * write response err check log * resolving conflicts and io.Copy error handling --- server/.golangci.yml | 1 - server/channels/api4/brand.go | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/server/.golangci.yml b/server/.golangci.yml index 4ce0f954c8..4f172e8f61 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -61,7 +61,6 @@ issues: path: "\ channels/api4/apitestlib.go|\ channels/api4/bot_test.go|\ - channels/api4/brand.go|\ channels/api4/channel.go|\ channels/api4/channel_test.go|\ channels/api4/cloud.go|\ diff --git a/server/channels/api4/brand.go b/server/channels/api4/brand.go index 2e8e60de7d..0d1ff1b23c 100644 --- a/server/channels/api4/brand.go +++ b/server/channels/api4/brand.go @@ -8,6 +8,7 @@ import ( "net/http" "github.com/mattermost/mattermost/server/public/model" + "github.com/mattermost/mattermost/server/public/shared/mlog" "github.com/mattermost/mattermost/server/v8/channels/audit" ) @@ -23,16 +24,24 @@ func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { img, err := c.App.GetBrandImage(c.AppContext) if err != nil { w.WriteHeader(http.StatusNotFound) - w.Write(nil) + if _, err := w.Write(nil); err != nil { + c.Logger.Warn("Error while writing response", mlog.Err(err)) + } return } w.Header().Set("Content-Type", "image/png") - w.Write(img) + if _, err := w.Write(img); err != nil { + c.Logger.Warn("Error while writing response", mlog.Err(err)) + } } func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { - defer io.Copy(io.Discard, r.Body) + defer func() { + if _, err := io.Copy(io.Discard, r.Body); err != nil { + c.Logger.Warn("Error discarding request body", mlog.Err(err)) + } + }() if r.ContentLength > *c.App.Config().FileSettings.MaxFileSize { c.Err = model.NewAppError("uploadBrandImage", "api.admin.upload_brand_image.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)