From bb8aabc15e1cf371eae0b75592af4ecc034596b9 Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Mon, 12 May 2025 13:41:59 +0200 Subject: [PATCH] [MM-61765] Fix errcheck issues in server/channels/app/platform/license.go (#30954) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [MM-61765] Fix errcheck issues in server/channels/app/platform/license.go - Removed the errcheck exception for license.go from .golangci.yml - Added proper error handling for RemoveLicense() calls - Added proper error handling for ReloadConfig() and InvalidateAllCaches() calls - Updated variable names to avoid conflicts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * simplify naming --------- Co-authored-by: Claude --- server/.golangci.yml | 1 - server/channels/app/platform/license.go | 42 +++++++++++++++++-------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/server/.golangci.yml b/server/.golangci.yml index 315362a967..544490d2d0 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -94,7 +94,6 @@ issues: channels/app/helper_test.go|\ channels/app/permissions_test.go|\ channels/app/platform/helper_test.go|\ - channels/app/platform/license.go|\ channels/store/localcachelayer/channel_layer.go|\ channels/store/localcachelayer/channel_layer_test.go|\ channels/store/localcachelayer/emoji_layer.go|\ diff --git a/server/channels/app/platform/license.go b/server/channels/app/platform/license.go index 2b7fae0698..87bb48ad1e 100644 --- a/server/channels/app/platform/license.go +++ b/server/channels/app/platform/license.go @@ -183,15 +183,16 @@ func (ps *PlatformService) SaveLicense(licenseBytes []byte) (*model.License, *mo record.Id = license.Id record.Bytes = string(licenseBytes) - nErr := ps.Store.License().Save(record) - if nErr != nil { - ps.RemoveLicense() + if err := ps.Store.License().Save(record); err != nil { + if appErr := ps.RemoveLicense(); appErr != nil { + ps.logger.Error("Failed to remove license after saving it to the license store failed", mlog.Err(appErr)) + } var appErr *model.AppError switch { - case errors.As(nErr, &appErr): + case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("addLicense", "api.license.add_license.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) + return nil, model.NewAppError("addLicense", "api.license.add_license.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -199,8 +200,11 @@ func (ps *PlatformService) SaveLicense(licenseBytes []byte) (*model.License, *mo sysVar.Name = model.SystemActiveLicenseId sysVar.Value = license.Id if err := ps.Store.System().SaveOrUpdate(sysVar); err != nil { - ps.RemoveLicense() - return nil, model.NewAppError("addLicense", "api.license.add_license.save_active.app_error", nil, "", http.StatusInternalServerError) + appErr := ps.RemoveLicense() + if appErr != nil { + ps.logger.Error("Failed to remove license after saving it to the system store failed", mlog.Err(appErr)) + } + return nil, model.NewAppError("addLicense", "api.license.add_license.save_active.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // only on prem licenses set this in the first place if !license.IsCloud() { @@ -210,8 +214,12 @@ func (ps *PlatformService) SaveLicense(licenseBytes []byte) (*model.License, *mo } } - ps.ReloadConfig() - ps.InvalidateAllCaches() + if err := ps.ReloadConfig(); err != nil { + ps.logger.Warn("Failed to reload config after saving license", mlog.Err(err)) + } + if appErr := ps.InvalidateAllCaches(); appErr != nil { + ps.logger.Warn("Failed to invalidate cache after saving license", mlog.Err(appErr)) + } return &license, nil } @@ -295,8 +303,12 @@ func (ps *PlatformService) RemoveLicense() *model.AppError { } ps.SetLicense(nil) - ps.ReloadConfig() - ps.InvalidateAllCaches() + if err := ps.ReloadConfig(); err != nil { + ps.logger.Warn("Failed to reload config after removing license", mlog.Err(err)) + } + if appErr := ps.InvalidateAllCaches(); appErr != nil { + ps.logger.Warn("Failed to invalidate cache after removing license", mlog.Err(appErr)) + } return nil } @@ -352,8 +364,12 @@ func (ps *PlatformService) RequestTrialLicense(trialRequest *model.TrialLicenseR return err } - ps.ReloadConfig() - ps.InvalidateAllCaches() + if err := ps.ReloadConfig(); err != nil { + ps.logger.Warn("Failed to reload config after requesting trial license", mlog.Err(err)) + } + if appErr := ps.InvalidateAllCaches(); appErr != nil { + ps.logger.Warn("Failed to invalidate cache after requesting trial license", mlog.Err(appErr)) + } return nil }