From 4b5d56a8c2dad845ef2368f78373dd240b49fea2 Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Thu, 23 Jun 2022 12:54:46 +0300 Subject: [PATCH] review some possible nil error panics (#20518) --- app/plugin_api_tests/test_set_profile_image_plugin/main.go | 2 +- app/plugin_install.go | 4 +--- app/user.go | 6 +++++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/plugin_api_tests/test_set_profile_image_plugin/main.go b/app/plugin_api_tests/test_set_profile_image_plugin/main.go index 9644193db8..6a1689284d 100644 --- a/app/plugin_api_tests/test_set_profile_image_plugin/main.go +++ b/app/plugin_api_tests/test_set_profile_image_plugin/main.go @@ -58,7 +58,7 @@ func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model byteReader := bytes.NewReader(imageProfile) img2, _, err2 := image.Decode(byteReader) if err2 != nil { - return nil, err.Error() + return nil, err2.Error() } if img2.At(2, 3) != colorful { return nil, fmt.Sprintf("color mismatch %v != %v", img2.At(2, 3), colorful) diff --git a/app/plugin_install.go b/app/plugin_install.go index 64df159098..a700f94916 100644 --- a/app/plugin_install.go +++ b/app/plugin_install.go @@ -46,7 +46,6 @@ import ( "path/filepath" "github.com/blang/semver" - "github.com/pkg/errors" "github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/shared/filestore" @@ -199,8 +198,7 @@ func (ch *Channels) InstallMarketplacePlugin(request *model.InstallMarketplacePl if prepackagedPlugin != nil { fileReader, err := os.Open(prepackagedPlugin.Path) if err != nil { - err = errors.Wrapf(err, "failed to open prepackaged plugin %s", prepackagedPlugin.Path) - return nil, model.NewAppError("InstallMarketplacePlugin", "app.plugin.install_marketplace_plugin.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("InstallMarketplacePlugin", "app.plugin.install_marketplace_plugin.app_error", nil, fmt.Sprintf("failed to open prepackaged plugin %s: %s", prepackagedPlugin.Path, err.Error()), http.StatusInternalServerError) } defer fileReader.Close() diff --git a/app/user.go b/app/user.go index 1fb1e7be2f..563d4e644c 100644 --- a/app/user.go +++ b/app/user.go @@ -1658,10 +1658,14 @@ func (a *App) SendEmailVerification(user *model.User, newEmail, redirect string) } if _, err := a.GetStatus(user.Id); err != nil { + if err.StatusCode != http.StatusNotFound { + return err + } eErr := a.Srv().EmailService.SendVerifyEmail(newEmail, user.Locale, a.GetSiteURL(), token.Token, redirect) if eErr != nil { return model.NewAppError("SendVerifyEmail", "api.user.send_verify_email_and_forget.failed.error", nil, eErr.Error(), http.StatusInternalServerError) } + return nil } @@ -2310,7 +2314,7 @@ func (a *App) ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysad appErr := a.Srv().Store.Bot().PermanentDelete(bot.UserId) if appErr != nil { - return nil, model.NewAppError("ConvertBotToUser", "app.user.convert_bot_to_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ConvertBotToUser", "app.user.convert_bot_to_user.app_error", nil, appErr.Error(), http.StatusInternalServerError) } return user, nil