Skip to content

Commit

Permalink
Fixed errcheck issues in server/channels/api4/group.go (mattermost#28404
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Aryakoste authored Oct 5, 2024
1 parent 88a8053 commit af9eb19
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 19 deletions.
1 change: 0 additions & 1 deletion server/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ issues:
channels/api4/export.go|\
channels/api4/export_test.go|\
channels/api4/file_test.go|\
channels/api4/group.go|\
channels/api4/group_local.go|\
channels/api4/handlers_test.go|\
channels/api4/import_test.go|\
Expand Down
73 changes: 55 additions & 18 deletions server/channels/api4/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"

"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/v8/channels/app"
"github.com/mattermost/mattermost/server/v8/channels/audit"
"github.com/mattermost/mattermost/server/v8/channels/store"
Expand Down Expand Up @@ -146,7 +147,9 @@ func getGroup(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func createGroup(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -206,7 +209,9 @@ func createGroup(c *Context, w http.ResponseWriter, r *http.Request) {
}
auditRec.Success()
w.WriteHeader(http.StatusCreated)
w.Write(js)
if _, err := w.Write(js); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -303,7 +308,9 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
}

auditRec.Success()
w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func linkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -389,7 +396,9 @@ func linkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
auditRec.Success()
w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func getGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -437,7 +446,9 @@ func getGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func getGroupSyncables(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -479,7 +490,9 @@ func getGroupSyncables(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func patchGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -566,7 +579,9 @@ func patchGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
auditRec.Success()
w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func unlinkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -726,7 +741,9 @@ func getGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func getGroupStats(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -766,7 +783,9 @@ func getGroupStats(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func getGroupsByUserId(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -802,7 +821,9 @@ func getGroupsByUserId(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func getGroupsByChannel(c *Context, w http.ResponseWriter, r *http.Request) {
Expand All @@ -820,7 +841,9 @@ func getGroupsByChannel(c *Context, w http.ResponseWriter, r *http.Request) {
c.Err = appErr
return
}
w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func getGroupsByTeam(c *Context, w http.ResponseWriter, r *http.Request) {
Expand All @@ -839,7 +862,9 @@ func getGroupsByTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.Err = appError
return
}
w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func getGroupsByTeamCommon(c *Context, r *http.Request) ([]byte, *model.AppError) {
Expand Down Expand Up @@ -973,7 +998,9 @@ func getGroupsAssociatedToChannelsByTeam(c *Context, w http.ResponseWriter, r *h
return
}

w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -1138,7 +1165,9 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func deleteGroup(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -1190,7 +1219,9 @@ func deleteGroup(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
auditRec.Success()
w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func restoreGroup(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -1244,7 +1275,9 @@ func restoreGroup(c *Context, w http.ResponseWriter, r *http.Request) {
}

auditRec.Success()
w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func addGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -1303,7 +1336,9 @@ func addGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
auditRec.Success()
w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

func deleteGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -1362,7 +1397,9 @@ func deleteGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
auditRec.Success()
w.Write(b)
if _, err := w.Write(b); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

// hasPermissionToReadGroupMembers check if a user has the permission to read the list of members of a given team.
Expand Down

0 comments on commit af9eb19

Please sign in to comment.