From a28a967eba3ce8536263fee66fa4922438f75648 Mon Sep 17 00:00:00 2001 From: Tim Scheuermann Date: Thu, 18 Aug 2022 11:01:37 +0200 Subject: [PATCH] MM-45991 Wrap errors (#20785) --- app/admin.go | 10 +- app/admin_advisor.go | 6 +- app/analytics.go | 42 +- app/app.go | 8 +- app/app_iface.go | 8 +- app/audit.go | 8 +- app/authentication.go | 24 +- app/auto_responder.go | 2 +- app/bot.go | 66 +- app/brand.go | 10 +- app/channel.go | 342 ++++---- app/channel_category.go | 32 +- app/command.go | 52 +- app/compliance.go | 10 +- app/email/email.go | 6 +- app/emoji.go | 38 +- app/expirynotify.go | 2 +- app/export.go | 24 +- app/file.go | 54 +- app/group.go | 130 +-- app/import.go | 4 +- app/import_functions.go | 116 +-- app/import_functions_test.go | 34 +- app/integration_action.go | 14 +- app/integrations.go | 2 +- app/job.go | 10 +- app/ldap.go | 10 +- app/license.go | 16 +- app/login.go | 2 +- app/notification.go | 6 +- app/notification_push.go | 6 +- app/oauth.go | 70 +- app/oauth_test.go | 2 +- app/onboarding.go | 4 +- app/permissions.go | 20 +- app/permissions_migrations.go | 6 +- app/platform/config.go | 4 +- app/plugin.go | 28 +- app/plugin_api.go | 6 +- app/plugin_install.go | 42 +- app/plugin_key_value_store.go | 18 +- app/plugin_signature.go | 8 +- app/plugin_statuses.go | 6 +- app/post.go | 114 +-- app/post_helpers.go | 4 +- app/preference.go | 6 +- app/product_notices.go | 12 +- app/reaction.go | 12 +- app/remote_cluster.go | 18 +- app/role.go | 26 +- app/saml.go | 20 +- app/scheme.go | 28 +- app/server.go | 14 +- app/session.go | 60 +- app/shared_channel.go | 12 +- app/slashcommands/auto_users.go | 8 +- app/status.go | 10 +- app/syncables.go | 6 +- app/team.go | 266 +++--- app/terms_of_service.go | 12 +- app/upload.go | 20 +- app/usage.go | 6 +- app/user.go | 268 +++--- app/user_terms_of_service.go | 8 +- app/webhook.go | 74 +- jobs/base_workers.go | 2 +- jobs/import_process/worker.go | 4 +- jobs/jobs.go | 38 +- .../advanced_permissions_phase_2.go | 4 +- jobs/migrations/migrations.go | 2 +- jobs/migrations/worker.go | 2 +- jobs/resend_invitation_email/worker.go | 4 +- manualtesting/manual_testing.go | 8 +- model/client4.go | 778 +++++++++--------- model/command.go | 2 +- model/config.go | 39 +- model/file_info.go | 2 +- model/incoming_webhook.go | 36 +- model/integration_action.go | 8 +- model/upload_session.go | 2 +- model/user.go | 2 +- model/utils.go | 5 +- model/utils_test.go | 4 +- model/websocket_client.go | 8 +- services/searchengine/bleveengine/bleve.go | 24 +- .../bleveengine/indexer/indexing_job.go | 26 +- services/searchengine/bleveengine/search.go | 28 +- services/slackimport/slackimport.go | 4 +- utils/license.go | 2 +- web/context.go | 6 +- web/saml.go | 4 +- web/webhook.go | 2 +- 92 files changed, 1681 insertions(+), 1677 deletions(-) diff --git a/app/admin.go b/app/admin.go index 7abca6951c..3a139ef2e2 100644 --- a/app/admin.go +++ b/app/admin.go @@ -71,7 +71,7 @@ func (s *Server) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) logFile := config.GetLogFileLocation(*s.platform.Config().LogSettings.FileLocation) file, err := os.Open(logFile) if err != nil { - return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, "", http.StatusInternalServerError).Wrap(err) } defer file.Close() @@ -91,17 +91,17 @@ func (s *Server) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) } lineEndPos, err := file.Seek(endOffset, io.SeekEnd) if err != nil { - return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, "", http.StatusInternalServerError).Wrap(err) } for { pos, err := file.Seek(searchPos, io.SeekCurrent) if err != nil { - return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, "", http.StatusInternalServerError).Wrap(err) } _, err = file.ReadAt(b, pos) if err != nil { - return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, "", http.StatusInternalServerError).Wrap(err) } if b[0] == newLine[0] || pos == 0 { @@ -110,7 +110,7 @@ func (s *Server) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) line := make([]byte, lineEndPos-pos) _, err := file.ReadAt(line, pos) if err != nil { - return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, "", http.StatusInternalServerError).Wrap(err) } lines = append(lines, string(line)) } diff --git a/app/admin_advisor.go b/app/admin_advisor.go index 6a71e3a83c..ca588b21f7 100644 --- a/app/admin_advisor.go +++ b/app/admin_advisor.go @@ -17,7 +17,7 @@ import ( func (a *App) GetWarnMetricsStatus() (map[string]*model.WarnMetricStatus, *model.AppError) { systemDataList, nErr := a.Srv().Store.System().Get() if nErr != nil { - return nil, model.NewAppError("GetWarnMetricsStatus", "app.system.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetWarnMetricsStatus", "app.system.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } isE0Edition := model.BuildEnterpriseReady == "true" // license == nil was already validated upstream @@ -236,7 +236,7 @@ func (a *App) setWarnMetricsStatusForId(warnMetricId string, status string) *mod Name: warnMetricId, Value: status, }); err != nil { - return model.NewAppError("setWarnMetricsStatusForId", "app.system.warn_metric.store.app_error", map[string]any{"WarnMetricName": warnMetricId}, err.Error(), http.StatusInternalServerError) + return model.NewAppError("setWarnMetricsStatusForId", "app.system.warn_metric.store.app_error", map[string]any{"WarnMetricName": warnMetricId}, "", http.StatusInternalServerError).Wrap(err) } return nil } @@ -253,7 +253,7 @@ func (a *App) RequestLicenseAndAckWarnMetric(c *request.Context, warnMetricId st registeredUsersCount, err := a.Srv().Store.User().Count(model.UserCountOptions{}) if err != nil { - return model.NewAppError("RequestLicenseAndAckWarnMetric", "api.license.request_trial_license.fail_get_user_count.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("RequestLicenseAndAckWarnMetric", "api.license.request_trial_license.fail_get_user_count.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if err := a.Channels().RequestTrialLicense(c.Session().UserId, int(registeredUsersCount), true, true); err != nil { diff --git a/app/analytics.go b/app/analytics.go index b7394db4a3..c7b2288749 100644 --- a/app/analytics.go +++ b/app/analytics.go @@ -22,7 +22,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo var systemUserCount int64 systemUserCount, err := a.Srv().Store.User().Count(model.UserCountOptions{}) if err != nil { - return nil, model.NewAppError("GetAnalytics", "app.user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAnalytics", "app.user.get_total_users_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if systemUserCount > int64(*a.Config().AnalyticsSettings.MaxUsersForStatistics) { @@ -49,7 +49,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g.Go(func() error { var err error if openChannelsCount, err = a.Srv().Store.Channel().AnalyticsTypeCount(teamID, model.ChannelTypeOpen); err != nil { - return model.NewAppError("GetAnalytics", "app.channel.analytics_type_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.channel.analytics_type_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -58,7 +58,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g.Go(func() error { var err error if privateChannelsCount, err = a.Srv().Store.Channel().AnalyticsTypeCount(teamID, model.ChannelTypePrivate); err != nil { - return model.NewAppError("GetAnalytics", "app.channel.analytics_type_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.channel.analytics_type_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -69,7 +69,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g.Go(func() error { var err error if inactiveUsersCount, err = a.Srv().Store.User().AnalyticsGetInactiveUsersCount(); err != nil { - return model.NewAppError("GetAnalytics", "app.user.analytics_get_inactive_users_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.user.analytics_get_inactive_users_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -77,7 +77,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g.Go(func() error { var err error if usersCount, err = a.Srv().Store.User().Count(model.UserCountOptions{TeamId: teamID}); err != nil { - return model.NewAppError("GetAnalytics", "app.user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.user.get_total_users_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -88,7 +88,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g.Go(func() error { var err error if postsCount, err = a.Srv().Store.Post().AnalyticsPostCount(&model.PostCountOptions{TeamId: teamID}); err != nil { - return model.NewAppError("GetAnalytics", "app.post.analytics_posts_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.post.analytics_posts_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -98,7 +98,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g.Go(func() error { var err error if teamsCount, err = a.Srv().Store.Team().AnalyticsTeamCount(nil); err != nil { - return model.NewAppError("GetAnalytics", "app.team.analytics_team_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.team.analytics_team_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -107,7 +107,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g.Go(func() error { var err error if dailyActiveUsersCount, err = a.Srv().Store.User().AnalyticsActiveCount(DayMilliseconds, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false}); err != nil { - return model.NewAppError("GetAnalytics", "app.user.analytics_daily_active_users.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.user.analytics_daily_active_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -116,7 +116,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g.Go(func() error { var err error if monthlyActiveUsersCount, err = a.Srv().Store.User().AnalyticsActiveCount(MonthMilliseconds, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false}); err != nil { - return model.NewAppError("GetAnalytics", "app.user.analytics_daily_active_users.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.user.analytics_daily_active_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -186,7 +186,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo YesterdayOnly: false, }) if nErr != nil { - return nil, model.NewAppError("GetAnalytics", "app.post.analytics_posts_count_by_day.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAnalytics", "app.post.analytics_posts_count_by_day.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return analyticsRows, nil @@ -201,7 +201,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo YesterdayOnly: false, }) if nErr != nil { - return nil, model.NewAppError("GetAnalytics", "app.post.analytics_posts_count_by_day.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAnalytics", "app.post.analytics_posts_count_by_day.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return analyticsRows, nil @@ -213,7 +213,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo analyticsRows, nErr := a.Srv().Store.Post().AnalyticsUserCountsWithPostsByDay(teamID) if nErr != nil { - return nil, model.NewAppError("GetAnalytics", "app.post.analytics_user_counts_posts_by_day.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAnalytics", "app.post.analytics_user_counts_posts_by_day.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return analyticsRows, nil @@ -232,7 +232,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g2.Go(func() error { var err error if incomingWebhookCount, err = a.Srv().Store.Webhook().AnalyticsIncomingCount(teamID); err != nil { - return model.NewAppError("GetAnalytics", "app.webhooks.analytics_incoming_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.webhooks.analytics_incoming_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -241,7 +241,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g2.Go(func() error { var err error if outgoingWebhookCount, err = a.Srv().Store.Webhook().AnalyticsOutgoingCount(teamID); err != nil { - return model.NewAppError("GetAnalytics", "app.webhooks.analytics_outgoing_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.webhooks.analytics_outgoing_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -250,7 +250,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g2.Go(func() error { var err error if commandsCount, err = a.Srv().Store.Command().AnalyticsCommandCount(teamID); err != nil { - return model.NewAppError("GetAnalytics", "app.analytics.getanalytics.internal_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.analytics.getanalytics.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -259,7 +259,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g2.Go(func() error { var err error if sessionsCount, err = a.Srv().Store.Session().AnalyticsSessionCount(); err != nil { - return model.NewAppError("GetAnalytics", "app.session.analytics_session_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.session.analytics_session_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -270,7 +270,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g2.Go(func() error { var err error if filesCount, err = a.Srv().Store.Post().AnalyticsPostCount(&model.PostCountOptions{TeamId: teamID, MustHaveFile: true}); err != nil { - return model.NewAppError("GetAnalytics", "app.post.analytics_posts_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.post.analytics_posts_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -278,7 +278,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo g2.Go(func() error { var err error if hashtagsCount, err = a.Srv().Store.Post().AnalyticsPostCount(&model.PostCountOptions{TeamId: teamID, MustHaveHashtag: true}); err != nil { - return model.NewAppError("GetAnalytics", "app.post.analytics_posts_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetAnalytics", "app.post.analytics_posts_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil }) @@ -310,7 +310,7 @@ func (a *App) GetAnalytics(name string, teamID string) (model.AnalyticsRows, *mo func (a *App) GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError) { users, err := a.Srv().Store.User().GetRecentlyActiveUsersForTeam(teamID, 0, 100, nil) if err != nil { - return nil, model.NewAppError("GetRecentlyActiveUsersForTeam", "app.user.get_recently_active_users.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetRecentlyActiveUsersForTeam", "app.user.get_recently_active_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } userMap := make(map[string]*model.User) @@ -325,7 +325,7 @@ func (a *App) GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.Us func (a *App) GetRecentlyActiveUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { users, err := a.Srv().Store.User().GetRecentlyActiveUsersForTeam(teamID, page*perPage, perPage, viewRestrictions) if err != nil { - return nil, model.NewAppError("GetRecentlyActiveUsersForTeamPage", "app.user.get_recently_active_users.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetRecentlyActiveUsersForTeamPage", "app.user.get_recently_active_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return a.sanitizeProfiles(users, asAdmin), nil @@ -334,7 +334,7 @@ func (a *App) GetRecentlyActiveUsersForTeamPage(teamID string, page, perPage int func (a *App) GetNewUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { users, err := a.Srv().Store.User().GetNewUsersForTeam(teamID, page*perPage, perPage, viewRestrictions) if err != nil { - return nil, model.NewAppError("GetNewUsersForTeamPage", "app.user.get_new_users.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetNewUsersForTeamPage", "app.user.get_new_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return a.sanitizeProfiles(users, asAdmin), nil diff --git a/app/app.go b/app/app.go index 4ac48823f5..bcb6149b4d 100644 --- a/app/app.go +++ b/app/app.go @@ -61,11 +61,11 @@ func (a *App) Handle404(w http.ResponseWriter, r *http.Request) { func (s *Server) getSystemInstallDate() (int64, *model.AppError) { systemData, err := s.Store.System().GetByName(model.SystemInstallationDateKey) if err != nil { - return 0, model.NewAppError("getSystemInstallDate", "app.system.get_by_name.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("getSystemInstallDate", "app.system.get_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } value, err := strconv.ParseInt(systemData.Value, 10, 64) if err != nil { - return 0, model.NewAppError("getSystemInstallDate", "app.system_install_date.parse_int.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("getSystemInstallDate", "app.system_install_date.parse_int.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return value, nil } @@ -73,11 +73,11 @@ func (s *Server) getSystemInstallDate() (int64, *model.AppError) { func (s *Server) getFirstServerRunTimestamp() (int64, *model.AppError) { systemData, err := s.Store.System().GetByName(model.SystemFirstServerRunTimestampKey) if err != nil { - return 0, model.NewAppError("getFirstServerRunTimestamp", "app.system.get_by_name.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("getFirstServerRunTimestamp", "app.system.get_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } value, err := strconv.ParseInt(systemData.Value, 10, 64) if err != nil { - return 0, model.NewAppError("getFirstServerRunTimestamp", "app.system_install_date.parse_int.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("getFirstServerRunTimestamp", "app.system_install_date.parse_int.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return value, nil } diff --git a/app/app_iface.go b/app/app_iface.go index 7e979bf27a..bdf5aa54de 100644 --- a/app/app_iface.go +++ b/app/app_iface.go @@ -103,11 +103,13 @@ type AppIface interface { // DefaultChannelNames returns the list of system-wide default channel names. // // By default the list will be (not necessarily in this order): + // // ['town-square', 'off-topic'] + // // However, if TeamSettings.ExperimentalDefaultChannels contains a list of channels then that list will replace // 'off-topic' and be included in the return results in addition to 'town-square'. For example: - // ['town-square', 'game-of-thrones', 'wow'] // + // ['town-square', 'game-of-thrones', 'wow'] DefaultChannelNames(c request.CTX) []string // DeleteChannelScheme deletes a channels scheme and sets its SchemeId to nil. DeleteChannelScheme(c request.CTX, channel *model.Channel) (*model.Channel, *model.AppError) @@ -227,6 +229,8 @@ type AppIface interface { GetTeamSchemeChannelRoles(c request.CTX, teamID string) (guestRoleName string, userRoleName string, adminRoleName string, err *model.AppError) // GetTotalUsersStats is used for the DM list total GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions) (*model.UsersStats, *model.AppError) + // GetUserStatusesByIds used by apiV4 + GetUserStatusesByIds(userIDs []string) ([]*model.Status, *model.AppError) // HasRemote returns whether a given channelID is present in the channel remotes or not. HasRemote(channelID string, remoteID string) (bool, error) // HubRegister registers a connection to a hub. @@ -388,8 +392,6 @@ type AppIface interface { UserIsInAdminRoleGroup(userID, syncableID string, syncableType model.GroupSyncableType) (bool, *model.AppError) // VerifyPlugin checks that the given signature corresponds to the given plugin and matches a trusted certificate. VerifyPlugin(plugin, signature io.ReadSeeker) *model.AppError - //GetUserStatusesByIds used by apiV4 - GetUserStatusesByIds(userIDs []string) ([]*model.Status, *model.AppError) AccountMigration() einterfaces.AccountMigrationInterface ActivateMfa(userID, token string) *model.AppError AddChannelsToRetentionPolicy(policyID string, channelIDs []string) *model.AppError diff --git a/app/audit.go b/app/audit.go index 7b250c769e..e0e471c75e 100644 --- a/app/audit.go +++ b/app/audit.go @@ -29,9 +29,9 @@ func (a *App) GetAudits(userID string, limit int) (model.Audits, *model.AppError var outErr *store.ErrOutOfBounds switch { case errors.As(err, &outErr): - return nil, model.NewAppError("GetAudits", "app.audit.get.limit.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetAudits", "app.audit.get.limit.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("GetAudits", "app.audit.get.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAudits", "app.audit.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return audits, nil @@ -43,9 +43,9 @@ func (a *App) GetAuditsPage(userID string, page int, perPage int) (model.Audits, var outErr *store.ErrOutOfBounds switch { case errors.As(err, &outErr): - return nil, model.NewAppError("GetAuditsPage", "app.audit.get.limit.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetAuditsPage", "app.audit.get.limit.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("GetAuditsPage", "app.audit.get.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAuditsPage", "app.audit.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return audits, nil diff --git a/app/authentication.go b/app/authentication.go index f20589cd4e..6e23d3ea84 100644 --- a/app/authentication.go +++ b/app/authentication.go @@ -50,9 +50,9 @@ func (a *App) IsPasswordValid(password string) *model.AppError { var invErr *users.ErrInvalidPassword switch { case errors.As(err, &invErr): - return model.NewAppError("User.IsValid", invErr.Id(), map[string]any{"Min": *a.Config().PasswordSettings.MinimumLength}, "", http.StatusBadRequest) + return model.NewAppError("User.IsValid", invErr.Id(), map[string]any{"Min": *a.Config().PasswordSettings.MinimumLength}, "", http.StatusBadRequest).Wrap(err) default: - return model.NewAppError("User.IsValid", "app.valid_password_generic.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("User.IsValid", "app.valid_password_generic.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -66,7 +66,7 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa if err := users.CheckUserPassword(user, password); err != nil { if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil { - return model.NewAppError("CheckPasswordAndAllCriteria", "app.user.update_failed_pwd_attempts.app_error", nil, passErr.Error(), http.StatusInternalServerError) + return model.NewAppError("CheckPasswordAndAllCriteria", "app.user.update_failed_pwd_attempts.app_error", nil, "", http.StatusInternalServerError).Wrap(passErr) } a.InvalidateCacheForUser(user.Id) @@ -74,9 +74,9 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa var invErr *users.ErrInvalidPassword switch { case errors.As(err, &invErr): - return model.NewAppError("checkUserPassword", "api.user.check_user_password.invalid.app_error", nil, "user_id="+user.Id, http.StatusUnauthorized) + return model.NewAppError("checkUserPassword", "api.user.check_user_password.invalid.app_error", nil, "user_id="+user.Id, http.StatusUnauthorized).Wrap(err) default: - return model.NewAppError("checkUserPassword", "app.valid_password_generic.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("checkUserPassword", "app.valid_password_generic.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -85,7 +85,7 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa // about the MFA state of the user in question if mfaToken != "" { if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil { - return model.NewAppError("CheckPasswordAndAllCriteria", "app.user.update_failed_pwd_attempts.app_error", nil, passErr.Error(), http.StatusInternalServerError) + return model.NewAppError("CheckPasswordAndAllCriteria", "app.user.update_failed_pwd_attempts.app_error", nil, "", http.StatusInternalServerError).Wrap(passErr) } } @@ -95,7 +95,7 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa } if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, 0); passErr != nil { - return model.NewAppError("CheckPasswordAndAllCriteria", "app.user.update_failed_pwd_attempts.app_error", nil, passErr.Error(), http.StatusInternalServerError) + return model.NewAppError("CheckPasswordAndAllCriteria", "app.user.update_failed_pwd_attempts.app_error", nil, "", http.StatusInternalServerError).Wrap(passErr) } a.InvalidateCacheForUser(user.Id) @@ -115,7 +115,7 @@ func (a *App) DoubleCheckPassword(user *model.User, password string) *model.AppE if err := users.CheckUserPassword(user, password); err != nil { if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil { - return model.NewAppError("DoubleCheckPassword", "app.user.update_failed_pwd_attempts.app_error", nil, passErr.Error(), http.StatusInternalServerError) + return model.NewAppError("DoubleCheckPassword", "app.user.update_failed_pwd_attempts.app_error", nil, "", http.StatusInternalServerError).Wrap(passErr) } a.InvalidateCacheForUser(user.Id) @@ -123,14 +123,14 @@ func (a *App) DoubleCheckPassword(user *model.User, password string) *model.AppE var invErr *users.ErrInvalidPassword switch { case errors.As(err, &invErr): - return model.NewAppError("DoubleCheckPassword", "api.user.check_user_password.invalid.app_error", nil, "user_id="+user.Id, http.StatusUnauthorized) + return model.NewAppError("DoubleCheckPassword", "api.user.check_user_password.invalid.app_error", nil, "user_id="+user.Id, http.StatusUnauthorized).Wrap(err) default: - return model.NewAppError("DoubleCheckPassword", "app.valid_password_generic.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DoubleCheckPassword", "app.valid_password_generic.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, 0); passErr != nil { - return model.NewAppError("DoubleCheckPassword", "app.user.update_failed_pwd_attempts.app_error", nil, passErr.Error(), http.StatusInternalServerError) + return model.NewAppError("DoubleCheckPassword", "app.user.update_failed_pwd_attempts.app_error", nil, "", http.StatusInternalServerError).Wrap(passErr) } a.InvalidateCacheForUser(user.Id) @@ -209,7 +209,7 @@ func (a *App) CheckUserMfa(user *model.User, token string) *model.AppError { ok, err := mfa.New(a.Srv().Store.User()).ValidateToken(user.MfaSecret, token) if err != nil { - return model.NewAppError("CheckUserMfa", "mfa.validate_token.authenticate.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("CheckUserMfa", "mfa.validate_token.authenticate.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if !ok { diff --git a/app/auto_responder.go b/app/auto_responder.go index 9c5ffc5d75..ae12b93e60 100644 --- a/app/auto_responder.go +++ b/app/auto_responder.go @@ -43,7 +43,7 @@ func (a *App) SendAutoResponseIfNecessary(c request.CTX, channel *model.Channel, autoResponded, err := a.checkIfRespondedToday(post.CreateAt, post.ChannelId, receiverId) if err != nil { - return false, model.NewAppError("SendAutoResponseIfNecessary", "app.user.send_auto_response.app_error", nil, err.Error(), http.StatusInternalServerError) + return false, model.NewAppError("SendAutoResponseIfNecessary", "app.user.send_auto_response.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if autoResponded { return false, nil diff --git a/app/bot.go b/app/bot.go index d998f7a684..4efad7f8df 100644 --- a/app/bot.go +++ b/app/bot.go @@ -126,9 +126,9 @@ func (a *App) CreateBot(c request.CTX, bot *model.Bot) (*model.Bot, *model.AppEr default: code = "app.user.save.existing.app_error" } - return nil, model.NewAppError("CreateBot", code, nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateBot", code, nil, "", http.StatusBadRequest).Wrap(nErr) default: - return nil, model.NewAppError("CreateBot", "app.user.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateBot", "app.user.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } bot.UserId = user.Id @@ -141,7 +141,7 @@ func (a *App) CreateBot(c request.CTX, bot *model.Bot) (*model.Bot, *model.AppEr case errors.As(nErr, &appErr): // in case we haven't converted to plain error. return nil, appErr default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("CreateBot", "app.bot.createbot.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateBot", "app.bot.createbot.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -149,7 +149,7 @@ func (a *App) CreateBot(c request.CTX, bot *model.Bot) (*model.Bot, *model.AppEr ownerUser, err := a.Srv().Store.User().Get(context.Background(), bot.OwnerId) var nfErr *store.ErrNotFound if err != nil && !errors.As(err, &nfErr) { - return nil, model.NewAppError("CreateBot", "app.user.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateBot", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } else if ownerUser != nil { // Send a message to the bot's creator to inform them that the bot needs to be added // to a team and channel after it's created @@ -261,9 +261,9 @@ func (a *App) getOrCreateBot(botDef *model.Bot) (*model.Bot, *model.AppError) { default: code = "app.user.save.existing.app_error" } - return nil, model.NewAppError("getOrCreateBot", code, nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("getOrCreateBot", code, nil, "", http.StatusBadRequest).Wrap(nErr) default: - return nil, model.NewAppError("getOrCreateBot", "app.user.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getOrCreateBot", "app.user.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } botDef.UserId = user.Id @@ -277,7 +277,7 @@ func (a *App) getOrCreateBot(botDef *model.Bot) (*model.Bot, *model.AppError) { case errors.As(nErr, &nAppErr): // in case we haven't converted to plain error. return nil, nAppErr default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("getOrCreateBot", "app.bot.createbot.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getOrCreateBot", "app.bot.createbot.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } return savedBot, nil @@ -314,9 +314,9 @@ func (a *App) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("PatchBot", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("PatchBot", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("PatchBot", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("PatchBot", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -335,14 +335,14 @@ func (a *App) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, case errors.As(nErr, &appErr): return nil, appErr case errors.As(nErr, &invErr): - return nil, model.NewAppError("PatchBot", "app.user.update.find.app_error", nil, nErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("PatchBot", "app.user.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &conErr): - if cErr, ok := nErr.(*store.ErrConflict); ok && cErr.Resource == "Username" { - return nil, model.NewAppError("PatchBot", "app.user.save.username_exists.app_error", nil, nErr.Error(), http.StatusBadRequest) + if conErr.Resource == "Username" { + return nil, model.NewAppError("PatchBot", "app.user.save.username_exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) } - return nil, model.NewAppError("PatchBot", "app.user.save.email_exists.app_error", nil, nErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("PatchBot", "app.user.save.email_exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) default: - return nil, model.NewAppError("PatchBot", "app.user.update.finding.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("PatchBot", "app.user.update.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } a.InvalidateCacheForUser(user.Id) @@ -356,11 +356,11 @@ func (a *App) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, var appErr *model.AppError switch { case errors.As(nErr, &nfErr): - return nil, model.MakeBotNotFoundError(nfErr.ID) + return nil, model.MakeBotNotFoundError(nfErr.ID).Wrap(nErr) case errors.As(nErr, &appErr): // in case we haven't converted to plain error. return nil, appErr default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("PatchBot", "app.bot.patchbot.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("PatchBot", "app.bot.patchbot.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } return bot, nil @@ -373,9 +373,9 @@ func (a *App) GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model. var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.MakeBotNotFoundError(nfErr.ID) + return nil, model.MakeBotNotFoundError(nfErr.ID).Wrap(err) default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("GetBot", "app.bot.getbot.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetBot", "app.bot.getbot.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return bot, nil @@ -385,7 +385,7 @@ func (a *App) GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model. func (a *App) GetBots(options *model.BotGetOptions) (model.BotList, *model.AppError) { bots, err := a.Srv().Store.Bot().GetAll(options) if err != nil { - return nil, model.NewAppError("GetBots", "app.bot.getbots.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetBots", "app.bot.getbots.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bots, nil } @@ -397,9 +397,9 @@ func (a *App) UpdateBotActive(c request.CTX, botUserId string, active bool) (*mo var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("PatchBot", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("PatchBot", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("PatchBot", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("PatchBot", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -412,9 +412,9 @@ func (a *App) UpdateBotActive(c request.CTX, botUserId string, active bool) (*mo var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.MakeBotNotFoundError(nfErr.ID) + return nil, model.MakeBotNotFoundError(nfErr.ID).Wrap(nErr) default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("UpdateBotActive", "app.bot.getbot.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateBotActive", "app.bot.getbot.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -434,11 +434,11 @@ func (a *App) UpdateBotActive(c request.CTX, botUserId string, active bool) (*mo var appErr *model.AppError switch { case errors.As(nErr, &nfErr): - return nil, model.MakeBotNotFoundError(nfErr.ID) + return nil, model.MakeBotNotFoundError(nfErr.ID).Wrap(nErr) case errors.As(nErr, &appErr): // in case we haven't converted to plain error. return nil, appErr default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("PatchBot", "app.bot.patchbot.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("PatchBot", "app.bot.patchbot.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } } @@ -452,14 +452,14 @@ func (a *App) PermanentDeleteBot(botUserId string) *model.AppError { var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return model.NewAppError("PermanentDeleteBot", "app.bot.permenent_delete.bad_id", map[string]any{"user_id": invErr.Value}, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("PermanentDeleteBot", "app.bot.permenent_delete.bad_id", map[string]any{"user_id": invErr.Value}, "", http.StatusBadRequest).Wrap(err) default: // last fallback in case it doesn't map to an existing app error. - return model.NewAppError("PatchBot", "app.bot.permanent_delete.internal_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PatchBot", "app.bot.permanent_delete.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } if err := a.Srv().Store.User().PermanentDelete(botUserId); err != nil { - return model.NewAppError("PermanentDeleteBot", "app.user.permanent_delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteBot", "app.user.permanent_delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -472,9 +472,9 @@ func (a *App) UpdateBotOwner(botUserId, newOwnerId string) (*model.Bot, *model.A var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.MakeBotNotFoundError(nfErr.ID) + return nil, model.MakeBotNotFoundError(nfErr.ID).Wrap(err) default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("UpdateBotOwner", "app.bot.getbot.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateBotOwner", "app.bot.getbot.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -486,11 +486,11 @@ func (a *App) UpdateBotOwner(botUserId, newOwnerId string) (*model.Bot, *model.A var appErr *model.AppError switch { case errors.As(err, &nfErr): - return nil, model.MakeBotNotFoundError(nfErr.ID) + return nil, model.MakeBotNotFoundError(nfErr.ID).Wrap(err) case errors.As(err, &appErr): // in case we haven't converted to plain error. return nil, appErr default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("PatchBot", "app.bot.patchbot.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("PatchBot", "app.bot.patchbot.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -651,7 +651,7 @@ func (a *App) ConvertUserToBot(user *model.User) (*model.Bot, *model.AppError) { case errors.As(err, &appErr): // in case we haven't converted to plain error. return nil, appErr default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("CreateBot", "app.bot.createbot.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateBot", "app.bot.createbot.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return bot, nil diff --git a/app/brand.go b/app/brand.go index a5ab57c9d0..be3b6c32be 100644 --- a/app/brand.go +++ b/app/brand.go @@ -24,30 +24,30 @@ func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError { file, err := imageData.Open() if err != nil { - return model.NewAppError("SaveBrandImage", "brand.save_brand_image.open.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("SaveBrandImage", "brand.save_brand_image.open.app_error", nil, "", http.StatusBadRequest).Wrap(err) } defer file.Close() if err = checkImageLimits(file, *a.Config().FileSettings.MaxImageResolution); err != nil { - return model.NewAppError("SaveBrandImage", "brand.save_brand_image.check_image_limits.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("SaveBrandImage", "brand.save_brand_image.check_image_limits.app_error", nil, "", http.StatusBadRequest).Wrap(err) } img, _, err := a.ch.imgDecoder.Decode(file) if err != nil { - return model.NewAppError("SaveBrandImage", "brand.save_brand_image.decode.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("SaveBrandImage", "brand.save_brand_image.decode.app_error", nil, "", http.StatusBadRequest).Wrap(err) } buf := new(bytes.Buffer) err = a.ch.imgEncoder.EncodePNG(buf, img) if err != nil { - return model.NewAppError("SaveBrandImage", "brand.save_brand_image.encode.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SaveBrandImage", "brand.save_brand_image.encode.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } t := time.Now() a.MoveFile(BrandFilePath+BrandFileName, BrandFilePath+t.Format("2006-01-02T15:04:05")+".png") if _, err := a.WriteFile(buf, BrandFilePath+BrandFileName); err != nil { - return model.NewAppError("SaveBrandImage", "brand.save_brand_image.save_image.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SaveBrandImage", "brand.save_brand_image.save_image.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil diff --git a/app/channel.go b/app/channel.go index 74dd77938f..de39d06c3a 100644 --- a/app/channel.go +++ b/app/channel.go @@ -52,11 +52,13 @@ var _ product.ChannelService = (*channelsWrapper)(nil) // DefaultChannelNames returns the list of system-wide default channel names. // // By default the list will be (not necessarily in this order): +// // ['town-square', 'off-topic'] +// // However, if TeamSettings.ExperimentalDefaultChannels contains a list of channels then that list will replace // 'off-topic' and be included in the return results in addition to 'town-square'. For example: -// ['town-square', 'game-of-thrones', 'wow'] // +// ['town-square', 'game-of-thrones', 'wow'] func (a *App) DefaultChannelNames(c request.CTX) []string { names := []string{"town-square"} @@ -84,9 +86,9 @@ func (a *App) JoinDefaultChannels(c request.CTX, teamID string, user *model.User var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return model.NewAppError("JoinDefaultChannels", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("JoinDefaultChannels", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return model.NewAppError("JoinDefaultChannels", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("JoinDefaultChannels", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } } @@ -113,7 +115,7 @@ func (a *App) JoinDefaultChannels(c request.CTX, teamID string, user *model.User _, nErr = a.Srv().Store.Channel().SaveMember(cm) if histErr := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); histErr != nil { - return model.NewAppError("JoinDefaultChannels", "app.channel_member_history.log_join_event.internal_error", nil, histErr.Error(), http.StatusInternalServerError) + return model.NewAppError("JoinDefaultChannels", "app.channel_member_history.log_join_event.internal_error", nil, "", http.StatusInternalServerError).Wrap(histErr) } if *a.Config().ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages { @@ -136,12 +138,12 @@ func (a *App) JoinDefaultChannels(c request.CTX, teamID string, user *model.User switch { case errors.As(nErr, &cErr): if cErr.Resource == "ChannelMembers" { - return model.NewAppError("JoinDefaultChannels", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest) + return model.NewAppError("JoinDefaultChannels", "app.channel.save_member.exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) } case errors.As(nErr, &appErr): return appErr default: - return model.NewAppError("JoinDefaultChannels", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("JoinDefaultChannels", "app.channel.create_direct_channel.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -250,20 +252,20 @@ func (a *App) CreateChannel(c request.CTX, channel *model.Channel, addMember boo case errors.As(nErr, &invErr): switch { case invErr.Entity == "Channel" && invErr.Field == "DeleteAt": - return nil, model.NewAppError("CreateChannel", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("CreateChannel", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case invErr.Entity == "Channel" && invErr.Field == "Type": - return nil, model.NewAppError("CreateChannel", "store.sql_channel.save.direct_channel.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("CreateChannel", "store.sql_channel.save.direct_channel.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case invErr.Entity == "Channel" && invErr.Field == "Id": - return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.existing.app_error", nil, "id="+invErr.Value.(string), http.StatusBadRequest) + return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.existing.app_error", nil, "id="+invErr.Value.(string), http.StatusBadRequest).Wrap(nErr) } case errors.As(nErr, &cErr): - return sc, model.NewAppError("CreateChannel", store.ChannelExistsError, nil, cErr.Error(), http.StatusBadRequest) + return sc, model.NewAppError("CreateChannel", store.ChannelExistsError, nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, <Err): - return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.limit.app_error", nil, ltErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.limit.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &appErr): // in case we haven't converted to plain error. return nil, appErr default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("CreateChannel", "app.channel.create_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateChannel", "app.channel.create_channel.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -273,9 +275,9 @@ func (a *App) CreateChannel(c request.CTX, channel *model.Channel, addMember boo var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("CreateChannel", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("CreateChannel", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("CreateChannel", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateChannel", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -295,17 +297,17 @@ func (a *App) CreateChannel(c request.CTX, channel *model.Channel, addMember boo case errors.As(nErr, &cErr): switch cErr.Resource { case "ChannelMembers": - return nil, model.NewAppError("CreateChannel", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateChannel", "app.channel.save_member.exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) } case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("CreateChannel", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateChannel", "app.channel.create_direct_channel.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(channel.CreatorId, sc.Id, model.GetMillis()); err != nil { - return nil, model.NewAppError("CreateChannel", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateChannel", "app.channel_member_history.log_join_event.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.InvalidateCacheForUser(channel.CreatorId) @@ -416,7 +418,7 @@ func (a *App) handleCreationEvent(c request.CTX, userID, otherUserID string, cha func (a *App) createDirectChannel(c request.CTX, userID string, otherUserID string, channelOptions ...model.ChannelOption) (*model.Channel, *model.AppError) { users, err := a.Srv().Store.User().GetMany(context.Background(), []string{userID, otherUserID}) if err != nil { - return nil, model.NewAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if len(users) == 0 { @@ -457,34 +459,34 @@ func (a *App) createDirectChannelWithUser(c request.CTX, user, otherUser *model. case errors.As(nErr, &invErr): switch { case invErr.Entity == "Channel" && invErr.Field == "DeleteAt": - return nil, model.NewAppError("createDirectChannelWithUser", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("createDirectChannelWithUser", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case invErr.Entity == "Channel" && invErr.Field == "Type": - return nil, model.NewAppError("createDirectChannelWithUser", "store.sql_channel.save_direct_channel.not_direct.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("createDirectChannelWithUser", "store.sql_channel.save_direct_channel.not_direct.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case invErr.Entity == "Channel" && invErr.Field == "Id": - return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.existing.app_error", nil, "id="+invErr.Value.(string), http.StatusBadRequest) + return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.existing.app_error", nil, "id="+invErr.Value.(string), http.StatusBadRequest).Wrap(nErr) } case errors.As(nErr, &cErr): switch cErr.Resource { case "Channel": - return channel, model.NewAppError("createDirectChannelWithUser", store.ChannelExistsError, nil, cErr.Error(), http.StatusBadRequest) + return channel, model.NewAppError("createDirectChannelWithUser", store.ChannelExistsError, nil, "", http.StatusBadRequest).Wrap(nErr) case "ChannelMembers": - return nil, model.NewAppError("createDirectChannelWithUser", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("createDirectChannelWithUser", "app.channel.save_member.exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) } case errors.As(nErr, <Err): - return nil, model.NewAppError("createDirectChannelWithUser", "store.sql_channel.save_channel.limit.app_error", nil, ltErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("createDirectChannelWithUser", "store.sql_channel.save_channel.limit.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &appErr): // in case we haven't converted to plain error. return nil, appErr default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("createDirectChannelWithUser", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createDirectChannelWithUser", "app.channel.create_direct_channel.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil { - return nil, model.NewAppError("createDirectChannelWithUser", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createDirectChannelWithUser", "app.channel_member_history.log_join_event.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } if user.Id != otherUser.Id { if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(otherUser.Id, channel.Id, model.GetMillis()); err != nil { - return nil, model.NewAppError("createDirectChannelWithUser", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createDirectChannelWithUser", "app.channel_member_history.log_join_event.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -505,7 +507,7 @@ func (a *App) createDirectChannelWithUser(c request.CTX, user, otherUser *model. } if _, err := a.SaveSharedChannel(c, sc); err != nil { - return nil, model.NewAppError("CreateDirectChannel", "app.sharedchannel.dm_channel_creation.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateDirectChannel", "app.sharedchannel.dm_channel_creation.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -539,7 +541,7 @@ func (a *App) createGroupChannel(c request.CTX, userIDs []string) (*model.Channe users, err := a.Srv().Store.User().GetProfileByIds(context.Background(), userIDs, nil, true) if err != nil { - return nil, model.NewAppError("createGroupChannel", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createGroupChannel", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(users) != len(userIDs) { @@ -562,20 +564,20 @@ func (a *App) createGroupChannel(c request.CTX, userIDs []string) (*model.Channe case errors.As(nErr, &invErr): switch { case invErr.Entity == "Channel" && invErr.Field == "DeleteAt": - return nil, model.NewAppError("CreateChannel", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("CreateChannel", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case invErr.Entity == "Channel" && invErr.Field == "Type": - return nil, model.NewAppError("CreateChannel", "store.sql_channel.save.direct_channel.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("CreateChannel", "store.sql_channel.save.direct_channel.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case invErr.Entity == "Channel" && invErr.Field == "Id": - return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.existing.app_error", nil, "id="+invErr.Value.(string), http.StatusBadRequest) + return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.existing.app_error", nil, "id="+invErr.Value.(string), http.StatusBadRequest).Wrap(nErr) } case errors.As(nErr, &cErr): - return channel, model.NewAppError("CreateChannel", store.ChannelExistsError, nil, cErr.Error(), http.StatusBadRequest) + return channel, model.NewAppError("CreateChannel", store.ChannelExistsError, nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, <Err): - return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.limit.app_error", nil, ltErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.limit.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &appErr): // in case we haven't converted to plain error. return nil, appErr default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("CreateChannel", "app.channel.create_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateChannel", "app.channel.create_channel.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -595,16 +597,16 @@ func (a *App) createGroupChannel(c request.CTX, userIDs []string) (*model.Channe case errors.As(nErr, &cErr): switch cErr.Resource { case "ChannelMembers": - return nil, model.NewAppError("createGroupChannel", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("createGroupChannel", "app.channel.save_member.exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) } case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("createGroupChannel", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createGroupChannel", "app.channel.create_direct_channel.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil { - return nil, model.NewAppError("createGroupChannel", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createGroupChannel", "app.channel_member_history.log_join_event.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -618,7 +620,7 @@ func (a *App) GetGroupChannel(c request.CTX, userIDs []string) (*model.Channel, users, err := a.Srv().Store.User().GetProfileByIds(context.Background(), userIDs, nil, true) if err != nil { - return nil, model.NewAppError("GetGroupChannel", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroupChannel", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(users) != len(userIDs) { @@ -641,7 +643,7 @@ func (a *App) UpdateChannel(c request.CTX, channel *model.Channel) (*model.Chann var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("UpdateChannel", "app.channel.update.bad_id", nil, "", http.StatusBadRequest).Wrap(invErr) + return nil, model.NewAppError("UpdateChannel", "app.channel.update.bad_id", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): return nil, appErr default: @@ -738,7 +740,7 @@ func (a *App) postChannelPrivacyMessage(c request.CTX, user *model.User, channel } else { systemBot, err := a.GetSystemBot() if err != nil { - return model.NewAppError("postChannelPrivacyMessage", "api.channel.post_channel_privacy_message.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postChannelPrivacyMessage", "api.channel.post_channel_privacy_message.error", nil, "", http.StatusInternalServerError).Wrap(err) } authorId = systemBot.UserId @@ -760,7 +762,7 @@ func (a *App) postChannelPrivacyMessage(c request.CTX, user *model.User, channel } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("postChannelPrivacyMessage", "api.channel.post_channel_privacy_message.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postChannelPrivacyMessage", "api.channel.post_channel_privacy_message.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -772,7 +774,7 @@ func (a *App) RestoreChannel(c request.CTX, channel *model.Channel, userID strin } if err := a.Srv().Store.Channel().Restore(channel.Id, model.GetMillis()); err != nil { - return nil, model.NewAppError("RestoreChannel", "app.channel.restore.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("RestoreChannel", "app.channel.restore.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } channel.DeleteAt = 0 a.invalidateCacheForChannel(channel) @@ -789,9 +791,9 @@ func (a *App) RestoreChannel(c request.CTX, channel *model.Channel, userID strin var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("RestoreChannel", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("RestoreChannel", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("RestoreChannel", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("RestoreChannel", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } } @@ -1096,7 +1098,7 @@ func (a *App) PatchChannelModerationsForChannel(c request.CTX, channel *model.Ch return nil }) if cErr != nil { - return nil, model.NewAppError("PatchChannelModerationsForChannel", "api.channel.patch_channel_moderations.cache_invalidation.error", nil, cErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("PatchChannelModerationsForChannel", "api.channel.patch_channel_moderations.cache_invalidation.error", nil, "", http.StatusInternalServerError).Wrap(cErr) } return buildChannelModerations(c, channel.Type, memberRole, guestRole, higherScopedMemberRole, higherScopedGuestRole), nil @@ -1267,7 +1269,7 @@ func (a *App) UpdateChannelMemberNotifyProps(c request.CTX, data map[string]stri case errors.As(err, &appErr): return nil, appErr case errors.As(err, &nfErr): - return nil, model.NewAppError("updateMemberNotifyProps", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(nfErr) + return nil, model.NewAppError("updateMemberNotifyProps", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(err) default: return nil, model.NewAppError("updateMemberNotifyProps", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } @@ -1297,7 +1299,7 @@ func (a *App) updateChannelMember(c request.CTX, member *model.ChannelMember) (* case errors.As(err, &appErr): return nil, appErr case errors.As(err, &nfErr): - return nil, model.NewAppError("updateChannelMember", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(nfErr) + return nil, model.NewAppError("updateChannelMember", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(err) default: return nil, model.NewAppError("updateChannelMember", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } @@ -1341,21 +1343,21 @@ func (a *App) DeleteChannel(c request.CTX, channel *model.Channel, userID string var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return model.NewAppError("DeleteChannel", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("DeleteChannel", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return model.NewAppError("DeleteChannel", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteChannel", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } } ihcresult := <-ihc if ihcresult.NErr != nil { - return model.NewAppError("DeleteChannel", "app.webhooks.get_incoming_by_channel.app_error", nil, ihcresult.NErr.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteChannel", "app.webhooks.get_incoming_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(ihcresult.NErr) } ohcresult := <-ohc if ohcresult.NErr != nil { - return model.NewAppError("DeleteChannel", "app.webhooks.get_outgoing_by_channel.app_error", nil, ohcresult.NErr.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteChannel", "app.webhooks.get_outgoing_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(ohcresult.NErr) } incomingHooks := ihcresult.Data.([]*model.IncomingWebhook) @@ -1428,7 +1430,7 @@ func (a *App) DeleteChannel(c request.CTX, channel *model.Channel, userID string deleteAt := model.GetMillis() if err := a.Srv().Store.Channel().Delete(channel.Id, deleteAt); err != nil { - return model.NewAppError("DeleteChannel", "app.channel.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteChannel", "app.channel.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.invalidateCacheForChannel(channel) @@ -1449,7 +1451,7 @@ func (a *App) addUserToChannel(c request.CTX, user *model.User, channel *model.C if nErr != nil { var nfErr *store.ErrNotFound if !errors.As(nErr, &nfErr) { - return nil, model.NewAppError("AddUserToChannel", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AddUserToChannel", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } else { return channelMember, nil @@ -1489,7 +1491,7 @@ func (a *App) addUserToChannel(c request.CTX, user *model.User, channel *model.C } if nErr := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); nErr != nil { - return nil, model.NewAppError("AddUserToChannel", "app.channel_member_history.log_join_event.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AddUserToChannel", "app.channel_member_history.log_join_event.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } a.InvalidateCacheForUser(user.Id) @@ -1506,9 +1508,9 @@ func (a *App) AddUserToChannel(c request.CTX, user *model.User, channel *model.C var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("AddUserToChannel", "app.team.get_member.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("AddUserToChannel", "app.team.get_member.missing.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("AddUserToChannel", "app.team.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AddUserToChannel", "app.team.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -1545,7 +1547,7 @@ func (a *App) AddChannelMember(c request.CTX, userID string, channel *model.Chan if member, err := a.Srv().Store.Channel().GetMember(context.Background(), channel.Id, userID); err != nil { var nfErr *store.ErrNotFound if !errors.As(err, &nfErr) { - return nil, model.NewAppError("AddChannelMember", "app.channel.get_member.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AddChannelMember", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } else { return member, nil @@ -1632,7 +1634,7 @@ func (a *App) AddDirectChannels(c request.CTX, teamID string, user *model.User) func (a *App) PostUpdateChannelHeaderMessage(c request.CTX, userID string, channel *model.Channel, oldChannelHeader, newChannelHeader string) *model.AppError { user, err := a.Srv().Store.User().Get(context.Background(), userID) if err != nil { - return model.NewAppError("PostUpdateChannelHeaderMessage", "api.channel.post_update_channel_header_message_and_forget.retrieve_user.error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("PostUpdateChannelHeaderMessage", "api.channel.post_update_channel_header_message_and_forget.retrieve_user.error", nil, "", http.StatusBadRequest).Wrap(err) } var message string @@ -1657,7 +1659,7 @@ func (a *App) PostUpdateChannelHeaderMessage(c request.CTX, userID string, chann } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("", "api.channel.post_update_channel_header_message_and_forget.post.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("", "api.channel.post_update_channel_header_message_and_forget.post.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -1666,7 +1668,7 @@ func (a *App) PostUpdateChannelHeaderMessage(c request.CTX, userID string, chann func (a *App) PostUpdateChannelPurposeMessage(c request.CTX, userID string, channel *model.Channel, oldChannelPurpose string, newChannelPurpose string) *model.AppError { user, err := a.Srv().Store.User().Get(context.Background(), userID) if err != nil { - return model.NewAppError("PostUpdateChannelPurposeMessage", "app.channel.post_update_channel_purpose_message.retrieve_user.error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("PostUpdateChannelPurposeMessage", "app.channel.post_update_channel_purpose_message.retrieve_user.error", nil, "", http.StatusBadRequest).Wrap(err) } var message string @@ -1690,7 +1692,7 @@ func (a *App) PostUpdateChannelPurposeMessage(c request.CTX, userID string, chan }, } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("", "app.channel.post_update_channel_purpose_message.post.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("", "app.channel.post_update_channel_purpose_message.post.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -1699,7 +1701,7 @@ func (a *App) PostUpdateChannelPurposeMessage(c request.CTX, userID string, chan func (a *App) PostUpdateChannelDisplayNameMessage(c request.CTX, userID string, channel *model.Channel, oldChannelDisplayName, newChannelDisplayName string) *model.AppError { user, err := a.Srv().Store.User().Get(context.Background(), userID) if err != nil { - return model.NewAppError("PostUpdateChannelDisplayNameMessage", "api.channel.post_update_channel_displayname_message_and_forget.retrieve_user.error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("PostUpdateChannelDisplayNameMessage", "api.channel.post_update_channel_displayname_message_and_forget.retrieve_user.error", nil, "", http.StatusBadRequest).Wrap(err) } message := fmt.Sprintf(i18n.T("api.channel.post_update_channel_displayname_message_and_forget.updated_from"), user.Username, oldChannelDisplayName, newChannelDisplayName) @@ -1717,7 +1719,7 @@ func (a *App) PostUpdateChannelDisplayNameMessage(c request.CTX, userID string, } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("PostUpdateChannelDisplayNameMessage", "api.channel.post_update_channel_displayname_message_and_forget.create_post.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PostUpdateChannelDisplayNameMessage", "api.channel.post_update_channel_displayname_message_and_forget.create_post.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -1733,9 +1735,9 @@ func (s *Server) getChannel(c request.CTX, channelID string) (*model.Channel, *m var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetChannel", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannel", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetChannel", "app.channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannel", "app.channel.get.find.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return channel, nil @@ -1747,9 +1749,9 @@ func (a *App) GetChannels(c request.CTX, channelIDs []string) ([]*model.Channel, var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetChannel", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannel", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetChannel", "app.channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannel", "app.channel.get.find.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return channels, nil @@ -1769,9 +1771,9 @@ func (a *App) GetChannelByName(c request.CTX, channelName, teamID string, includ var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetChannelByName", "app.channel.get_by_name.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannelByName", "app.channel.get_by_name.missing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetChannelByName", "app.channel.get_by_name.existing.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelByName", "app.channel.get_by_name.existing.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1781,7 +1783,7 @@ func (a *App) GetChannelByName(c request.CTX, channelName, teamID string, includ func (a *App) GetChannelsByNames(c request.CTX, channelNames []string, teamID string) ([]*model.Channel, *model.AppError) { channels, err := a.Srv().Store.Channel().GetByNames(teamID, channelNames, true) if err != nil { - return nil, model.NewAppError("GetChannelsByNames", "app.channel.get_by_name.existing.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelsByNames", "app.channel.get_by_name.existing.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channels, nil } @@ -1794,9 +1796,9 @@ func (a *App) GetChannelByNameForTeamName(c request.CTX, channelName, teamName s var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetChannelByNameForTeamName", "app.team.get_by_name.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannelByNameForTeamName", "app.team.get_by_name.missing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetChannelByNameForTeamName", "app.team.get_by_name.app_error", nil, err.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannelByNameForTeamName", "app.team.get_by_name.app_error", nil, "", http.StatusNotFound).Wrap(err) } } @@ -1813,9 +1815,9 @@ func (a *App) GetChannelByNameForTeamName(c request.CTX, channelName, teamName s var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("GetChannelByNameForTeamName", "app.channel.get_by_name.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannelByNameForTeamName", "app.channel.get_by_name.missing.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("GetChannelByNameForTeamName", "app.channel.get_by_name.existing.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelByNameForTeamName", "app.channel.get_by_name.existing.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -1828,9 +1830,9 @@ func (s *Server) getChannelsForTeamForUser(c request.CTX, teamID string, userID var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.not_found.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1847,9 +1849,9 @@ func (a *App) GetChannelsForTeamForUserWithCursor(c request.CTX, teamID string, var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.not_found.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1862,9 +1864,9 @@ func (a *App) GetChannelsForUser(c request.CTX, userID string, includeDeleted bo var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.not_found.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1884,7 +1886,7 @@ func (a *App) GetAllChannels(c request.CTX, page, perPage int, opts model.Channe } channels, err := a.Srv().Store.Channel().GetAllChannels(page*perPage, perPage, storeOpts) if err != nil { - return nil, model.NewAppError("GetAllChannels", "app.channel.get_all_channels.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAllChannels", "app.channel.get_all_channels.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channels, nil @@ -1901,7 +1903,7 @@ func (a *App) GetAllChannelsCount(c request.CTX, opts model.ChannelSearchOpts) ( } count, err := a.Srv().Store.Channel().GetAllChannelsCount(storeOpts) if err != nil { - return 0, model.NewAppError("GetAllChannelsCount", "app.channel.get_all_channels_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("GetAllChannelsCount", "app.channel.get_all_channels_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return count, nil @@ -1913,9 +1915,9 @@ func (a *App) GetDeletedChannels(c request.CTX, teamID string, offset int, limit var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetDeletedChannels", "app.channel.get_deleted.missing.app_error", nil, err.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetDeletedChannels", "app.channel.get_deleted.missing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetDeletedChannels", "app.channel.get_deleted.existing.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetDeletedChannels", "app.channel.get_deleted.existing.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1925,7 +1927,7 @@ func (a *App) GetDeletedChannels(c request.CTX, teamID string, offset int, limit func (a *App) GetChannelsUserNotIn(c request.CTX, teamID string, userID string, offset int, limit int) (model.ChannelList, *model.AppError) { channels, err := a.Srv().Store.Channel().GetMoreChannels(teamID, userID, offset, limit) if err != nil { - return nil, model.NewAppError("GetChannelsUserNotIn", "app.channel.get_more_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelsUserNotIn", "app.channel.get_more_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channels, nil } @@ -1936,9 +1938,9 @@ func (a *App) GetPublicChannelsByIdsForTeam(c request.CTX, teamID string, channe var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetPublicChannelsByIdsForTeam", "app.channel.get_channels_by_ids.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetPublicChannelsByIdsForTeam", "app.channel.get_channels_by_ids.not_found.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetPublicChannelsByIdsForTeam", "app.channel.get_channels_by_ids.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPublicChannelsByIdsForTeam", "app.channel.get_channels_by_ids.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1948,7 +1950,7 @@ func (a *App) GetPublicChannelsByIdsForTeam(c request.CTX, teamID string, channe func (a *App) GetPublicChannelsForTeam(c request.CTX, teamID string, offset int, limit int) (model.ChannelList, *model.AppError) { list, err := a.Srv().Store.Channel().GetPublicChannelsForTeam(teamID, offset, limit) if err != nil { - return nil, model.NewAppError("GetPublicChannelsForTeam", "app.channel.get_public_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPublicChannelsForTeam", "app.channel.get_public_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, nil @@ -1957,7 +1959,7 @@ func (a *App) GetPublicChannelsForTeam(c request.CTX, teamID string, offset int, func (a *App) GetPrivateChannelsForTeam(c request.CTX, teamID string, offset int, limit int) (model.ChannelList, *model.AppError) { list, err := a.Srv().Store.Channel().GetPrivateChannelsForTeam(teamID, offset, limit) if err != nil { - return nil, model.NewAppError("GetPrivateChannelsForTeam", "app.channel.get_private_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPrivateChannelsForTeam", "app.channel.get_private_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, nil @@ -1973,9 +1975,9 @@ func (s *Server) getChannelMember(c request.CTX, channelID string, userID string var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetChannelMember", MissingChannelMemberError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannelMember", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetChannelMember", "app.channel.get_member.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelMember", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1985,7 +1987,7 @@ func (s *Server) getChannelMember(c request.CTX, channelID string, userID string func (a *App) GetChannelMembersPage(c request.CTX, channelID string, page, perPage int) (model.ChannelMembers, *model.AppError) { channelMembers, err := a.Srv().Store.Channel().GetMembers(channelID, page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetChannelMembersPage", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelMembersPage", "app.channel.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelMembers, nil @@ -1994,7 +1996,7 @@ func (a *App) GetChannelMembersPage(c request.CTX, channelID string, page, perPa func (a *App) GetChannelMembersTimezones(c request.CTX, channelID string) ([]string, *model.AppError) { membersTimezones, err := a.Srv().Store.Channel().GetChannelMembersTimezones(channelID) if err != nil { - return nil, model.NewAppError("GetChannelMembersTimezones", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelMembersTimezones", "app.channel.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } var timezones []string @@ -2011,7 +2013,7 @@ func (a *App) GetChannelMembersTimezones(c request.CTX, channelID string) ([]str func (a *App) GetChannelMembersByIds(c request.CTX, channelID string, userIDs []string) (model.ChannelMembers, *model.AppError) { members, err := a.Srv().Store.Channel().GetMembersByIds(channelID, userIDs) if err != nil { - return nil, model.NewAppError("GetChannelMembersByIds", "app.channel.get_members_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelMembersByIds", "app.channel.get_members_by_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return members, nil @@ -2020,7 +2022,7 @@ func (a *App) GetChannelMembersByIds(c request.CTX, channelID string, userIDs [] func (a *App) GetChannelMembersForUser(c request.CTX, teamID string, userID string) (model.ChannelMembers, *model.AppError) { channelMembers, err := a.Srv().Store.Channel().GetMembersForUser(teamID, userID) if err != nil { - return nil, model.NewAppError("GetChannelMembersForUser", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelMembersForUser", "app.channel.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelMembers, nil @@ -2029,7 +2031,7 @@ func (a *App) GetChannelMembersForUser(c request.CTX, teamID string, userID stri func (a *App) GetChannelMembersForUserWithPagination(c request.CTX, userID string, page, perPage int) ([]*model.ChannelMember, *model.AppError) { m, err := a.Srv().Store.Channel().GetMembersForUserWithPagination(userID, page, perPage) if err != nil { - return nil, model.NewAppError("GetChannelMembersForUserWithPagination", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelMembersForUserWithPagination", "app.channel.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } members := make([]*model.ChannelMember, 0, len(m)) @@ -2043,7 +2045,7 @@ func (a *App) GetChannelMembersForUserWithPagination(c request.CTX, userID strin func (a *App) GetChannelMembersWithTeamDataForUserWithPagination(c request.CTX, userID string, page, perPage int) (model.ChannelMembersWithTeamData, *model.AppError) { m, err := a.Srv().Store.Channel().GetMembersForUserWithPagination(userID, page, perPage) if err != nil { - return nil, model.NewAppError("GetChannelMembersForUserWithPagination", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelMembersForUserWithPagination", "app.channel.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return m, nil @@ -2052,7 +2054,7 @@ func (a *App) GetChannelMembersWithTeamDataForUserWithPagination(c request.CTX, func (a *App) GetChannelMemberCount(c request.CTX, channelID string) (int64, *model.AppError) { count, err := a.Srv().Store.Channel().GetMemberCount(channelID, true) if err != nil { - return 0, model.NewAppError("GetChannelMemberCount", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("GetChannelMemberCount", "app.channel.get_member_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return count, nil @@ -2061,7 +2063,7 @@ func (a *App) GetChannelMemberCount(c request.CTX, channelID string) (int64, *mo func (a *App) GetChannelFileCount(c request.CTX, channelID string) (int64, *model.AppError) { count, err := a.Srv().Store.Channel().GetFileCount(channelID) if err != nil { - return 0, model.NewAppError("SqlChannelStore.GetFileCount", "app.channel.get_file_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("SqlChannelStore.GetFileCount", "app.channel.get_file_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return count, nil @@ -2070,7 +2072,7 @@ func (a *App) GetChannelFileCount(c request.CTX, channelID string) (int64, *mode func (a *App) GetChannelGuestCount(c request.CTX, channelID string) (int64, *model.AppError) { count, err := a.Srv().Store.Channel().GetGuestCount(channelID, true) if err != nil { - return 0, model.NewAppError("SqlChannelStore.GetGuestCount", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("SqlChannelStore.GetGuestCount", "app.channel.get_member_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return count, nil @@ -2079,7 +2081,7 @@ func (a *App) GetChannelGuestCount(c request.CTX, channelID string) (int64, *mod func (a *App) GetChannelPinnedPostCount(c request.CTX, channelID string) (int64, *model.AppError) { count, err := a.Srv().Store.Channel().GetPinnedPostCount(channelID, true) if err != nil { - return 0, model.NewAppError("GetChannelPinnedPostCount", "app.channel.get_pinnedpost_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("GetChannelPinnedPostCount", "app.channel.get_pinnedpost_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return count, nil @@ -2088,7 +2090,7 @@ func (a *App) GetChannelPinnedPostCount(c request.CTX, channelID string) (int64, func (a *App) GetChannelCounts(c request.CTX, teamID string, userID string) (*model.ChannelCounts, *model.AppError) { counts, err := a.Srv().Store.Channel().GetChannelCounts(teamID, userID) if err != nil { - return nil, model.NewAppError("SqlChannelStore.GetChannelCounts", "app.channel.get_channel_counts.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SqlChannelStore.GetChannelCounts", "app.channel.get_channel_counts.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return counts, nil @@ -2100,9 +2102,9 @@ func (a *App) GetChannelUnread(c request.CTX, channelID, userID string) (*model. var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetChannelUnread", "app.channel.get_unread.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetChannelUnread", "app.channel.get_unread.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetChannelUnread", "app.channel.get_unread.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelUnread", "app.channel.get_unread.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -2132,9 +2134,9 @@ func (a *App) JoinChannel(c request.CTX, channel *model.Channel, userID string) var nfErr *store.ErrNotFound switch { case errors.As(uresult.NErr, &nfErr): - return model.NewAppError("CreateChannel", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("CreateChannel", MissingAccountError, nil, "", http.StatusNotFound).Wrap(uresult.NErr) default: - return model.NewAppError("CreateChannel", "app.user.get.app_error", nil, uresult.NErr.Error(), http.StatusInternalServerError) + return model.NewAppError("CreateChannel", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(uresult.NErr) } } @@ -2192,7 +2194,7 @@ func (a *App) postJoinChannelMessage(c request.CTX, user *model.User, channel *m } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("postJoinChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postJoinChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -2210,7 +2212,7 @@ func (a *App) postJoinTeamMessage(c request.CTX, user *model.User, channel *mode } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("postJoinTeamMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postJoinTeamMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -2243,9 +2245,9 @@ func (a *App) LeaveChannel(c request.CTX, channelID string, userID string) *mode var nfErr *store.ErrNotFound switch { case errors.As(cresult.NErr, &nfErr): - return model.NewAppError("LeaveChannel", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("LeaveChannel", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(cresult.NErr) default: - return model.NewAppError("LeaveChannel", "app.channel.get.find.app_error", nil, cresult.NErr.Error(), http.StatusInternalServerError) + return model.NewAppError("LeaveChannel", "app.channel.get.find.app_error", nil, "", http.StatusInternalServerError).Wrap(cresult.NErr) } } uresult := <-uc @@ -2253,14 +2255,14 @@ func (a *App) LeaveChannel(c request.CTX, channelID string, userID string) *mode var nfErr *store.ErrNotFound switch { case errors.As(uresult.NErr, &nfErr): - return model.NewAppError("LeaveChannel", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("LeaveChannel", MissingAccountError, nil, "", http.StatusNotFound).Wrap(uresult.NErr) default: - return model.NewAppError("LeaveChannel", "app.user.get.app_error", nil, uresult.NErr.Error(), http.StatusInternalServerError) + return model.NewAppError("LeaveChannel", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(uresult.NErr) } } ccresult := <-mcc if ccresult.NErr != nil { - return model.NewAppError("LeaveChannel", "app.channel.get_member_count.app_error", nil, ccresult.NErr.Error(), http.StatusInternalServerError) + return model.NewAppError("LeaveChannel", "app.channel.get_member_count.app_error", nil, "", http.StatusInternalServerError).Wrap(ccresult.NErr) } channel := cresult.Data.(*model.Channel) @@ -2307,7 +2309,7 @@ func (a *App) postLeaveChannelMessage(c request.CTX, user *model.User, channel * } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("postLeaveChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postLeaveChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -2337,7 +2339,7 @@ func (a *App) PostAddToChannelMessage(c request.CTX, user *model.User, addedUser } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("postAddToChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postAddToChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -2359,7 +2361,7 @@ func (a *App) postAddToTeamMessage(c request.CTX, user *model.User, addedUser *m } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("postAddToTeamMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postAddToTeamMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -2370,7 +2372,7 @@ func (a *App) postRemoveFromChannelMessage(c request.CTX, removerUserId string, if messageUserId == "" { systemBot, err := a.GetSystemBot() if err != nil { - return model.NewAppError("postRemoveFromChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postRemoveFromChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err) } messageUserId = systemBot.UserId @@ -2391,7 +2393,7 @@ func (a *App) postRemoveFromChannelMessage(c request.CTX, removerUserId string, } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("postRemoveFromChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postRemoveFromChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -2403,9 +2405,9 @@ func (a *App) removeUserFromChannel(c request.CTX, userIDToRemove string, remove var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return model.NewAppError("removeUserFromChannel", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("removeUserFromChannel", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return model.NewAppError("removeUserFromChannel", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("removeUserFromChannel", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } isGuest := user.IsGuest() @@ -2419,7 +2421,7 @@ func (a *App) removeUserFromChannel(c request.CTX, userIDToRemove string, remove if channel.IsGroupConstrained() && userIDToRemove != removerUserId && !user.IsBot { nonMembers, err := a.FilterNonGroupChannelMembers([]string{userIDToRemove}, channel) if err != nil { - return model.NewAppError("removeUserFromChannel", "api.channel.remove_user_from_channel.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("removeUserFromChannel", "api.channel.remove_user_from_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(nonMembers) == 0 { return model.NewAppError("removeUserFromChannel", "api.channel.remove_members.denied", map[string]any{"UserIDs": nonMembers}, "", http.StatusBadRequest) @@ -2432,10 +2434,10 @@ func (a *App) removeUserFromChannel(c request.CTX, userIDToRemove string, remove } if err := a.Srv().Store.Channel().RemoveMember(channel.Id, userIDToRemove); err != nil { - return model.NewAppError("removeUserFromChannel", "app.channel.remove_member.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("removeUserFromChannel", "app.channel.remove_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.ChannelMemberHistory().LogLeaveEvent(userIDToRemove, channel.Id, model.GetMillis()); err != nil { - return model.NewAppError("removeUserFromChannel", "app.channel_member_history.log_leave_event.internal_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("removeUserFromChannel", "app.channel_member_history.log_leave_event.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } if isGuest { @@ -2446,11 +2448,11 @@ func (a *App) removeUserFromChannel(c request.CTX, userIDToRemove string, remove if len(currentMembers) == 0 { teamMember, err := a.GetTeamMember(channel.TeamId, userIDToRemove) if err != nil { - return model.NewAppError("removeUserFromChannel", "api.team.remove_user_from_team.missing.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("removeUserFromChannel", "api.team.remove_user_from_team.missing.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if err := a.ch.srv.teamService.RemoveTeamMember(teamMember); err != nil { - return model.NewAppError("removeUserFromChannel", "api.team.remove_user_from_team.missing.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("removeUserFromChannel", "api.team.remove_user_from_team.missing.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if err = a.postProcessTeamMemberLeave(c, teamMember, removerUserId); err != nil { @@ -2523,9 +2525,9 @@ func (a *App) GetNumberOfChannelsOnTeam(c request.CTX, teamID string) (int, *mod var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return 0, model.NewAppError("GetNumberOfChannelsOnTeam", "app.channel.get_channels.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound) + return 0, model.NewAppError("GetNumberOfChannelsOnTeam", "app.channel.get_channels.not_found.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return 0, model.NewAppError("GetNumberOfChannelsOnTeam", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("GetNumberOfChannelsOnTeam", "app.channel.get_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return len(list), nil @@ -2594,7 +2596,7 @@ func (a *App) MarkChannelAsUnreadFromPost(c request.CTX, postID string, userID s channelUnread, nErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, unreadMentionsRoot, true) if nErr != nil { - return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } a.sendWebSocketPostUnreadEvent(c, channelUnread, postID, false) @@ -2628,9 +2630,9 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID st // In CRT Supported Client: badge on channel only sums mentions in root posts including and below the post that was marked. // In CRT Unsupported Client: badge on channel sums mentions in all posts (root & replies) including and below the post that was marked unread. if post.RootId == "" { - channelUnread, err := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, unreadMentionsRoot, true) - if err != nil { - return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err) + channelUnread, nErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, unreadMentionsRoot, true) + if nErr != nil { + return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } a.sendWebSocketPostUnreadEvent(c, channelUnread, postID, true) @@ -2648,9 +2650,9 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID st return nil, appErr } - channel, err := a.Srv().Store.Channel().Get(post.ChannelId, true) - if err != nil { - return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err) + channel, nErr := a.Srv().Store.Channel().Get(post.ChannelId, true) + if nErr != nil { + return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } if *a.Config().ServiceSettings.ThreadAutoFollow { @@ -2702,9 +2704,9 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID st } } - channelUnread, err := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, 0, false) - if err != nil { - return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err) + channelUnread, nErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, 0, false) + if nErr != nil { + return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } a.sendWebSocketPostUnreadEvent(c, channelUnread, postID, false) a.UpdateMobileAppBadge(userID) @@ -2735,7 +2737,7 @@ func (a *App) AutocompleteChannels(c request.CTX, userID, term string) (model.Ch channelList, err := a.Srv().Store.Channel().Autocomplete(userID, term, includeDeleted, user.IsGuest()) if err != nil { - return nil, model.NewAppError("AutocompleteChannels", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AutocompleteChannels", "app.channel.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelList, nil @@ -2752,7 +2754,7 @@ func (a *App) AutocompleteChannelsForTeam(c request.CTX, teamID, userID, term st channelList, err := a.Srv().Store.Channel().AutocompleteInTeam(teamID, userID, term, includeDeleted, user.IsGuest()) if err != nil { - return nil, model.NewAppError("AutocompleteChannels", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AutocompleteChannels", "app.channel.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelList, nil @@ -2765,7 +2767,7 @@ func (a *App) AutocompleteChannelsForSearch(c request.CTX, teamID string, userID channelList, err := a.Srv().Store.Channel().AutocompleteInTeamForSearch(teamID, userID, term, includeDeleted) if err != nil { - return nil, model.NewAppError("AutocompleteChannelsForSearch", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AutocompleteChannelsForSearch", "app.channel.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelList, nil @@ -2798,7 +2800,7 @@ func (a *App) SearchAllChannels(c request.CTX, term string, opts model.ChannelSe channelList, totalCount, err := a.Srv().Store.Channel().SearchAllChannels(term, storeOpts) if err != nil { - return nil, 0, model.NewAppError("SearchAllChannels", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("SearchAllChannels", "app.channel.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelList, totalCount, nil @@ -2811,7 +2813,7 @@ func (a *App) SearchChannels(c request.CTX, teamID string, term string) (model.C channelList, err := a.Srv().Store.Channel().SearchInTeam(teamID, term, includeDeleted) if err != nil { - return nil, model.NewAppError("SearchChannels", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchChannels", "app.channel.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelList, nil @@ -2822,7 +2824,7 @@ func (a *App) SearchArchivedChannels(c request.CTX, teamID string, term string, channelList, err := a.Srv().Store.Channel().SearchArchivedInTeam(teamID, term, userID) if err != nil { - return nil, model.NewAppError("SearchArchivedChannels", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchArchivedChannels", "app.channel.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelList, nil @@ -2835,7 +2837,7 @@ func (a *App) SearchChannelsForUser(c request.CTX, userID, teamID, term string) channelList, err := a.Srv().Store.Channel().SearchForUserInTeam(userID, teamID, term, includeDeleted) if err != nil { - return nil, model.NewAppError("SearchChannelsForUser", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchChannelsForUser", "app.channel.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelList, nil @@ -2848,7 +2850,7 @@ func (a *App) SearchGroupChannels(c request.CTX, userID, term string) (model.Cha channelList, err := a.Srv().Store.Channel().SearchGroupChannels(userID, term) if err != nil { - return nil, model.NewAppError("SearchGroupChannels", "app.channel.search_group_channels.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchGroupChannels", "app.channel.search_group_channels.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelList, nil } @@ -2857,7 +2859,7 @@ func (a *App) SearchChannelsUserNotIn(c request.CTX, teamID string, userID strin term = strings.TrimSpace(term) channelList, err := a.Srv().Store.Channel().SearchMore(userID, teamID, term) if err != nil { - return nil, model.NewAppError("SearchChannelsUserNotIn", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchChannelsUserNotIn", "app.channel.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelList, nil @@ -2910,7 +2912,7 @@ func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID st if updateThreads { err = a.Srv().Store.Thread().MarkAllAsReadByChannels(userID, channelIDs) if err != nil { - return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -2919,9 +2921,9 @@ func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID st var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -2972,25 +2974,25 @@ func (a *App) ViewChannel(c request.CTX, view *model.ChannelView, userID string, func (a *App) PermanentDeleteChannel(c request.CTX, channel *model.Channel) *model.AppError { if err := a.Srv().Store.Post().PermanentDeleteByChannel(channel.Id); err != nil { - return model.NewAppError("PermanentDeleteChannel", "app.post.permanent_delete_by_channel.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteChannel", "app.post.permanent_delete_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Channel().PermanentDeleteMembersByChannel(channel.Id); err != nil { - return model.NewAppError("PermanentDeleteChannel", "app.channel.remove_member.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteChannel", "app.channel.remove_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Webhook().PermanentDeleteIncomingByChannel(channel.Id); err != nil { - return model.NewAppError("PermanentDeleteChannel", "app.webhooks.permanent_delete_incoming_by_channel.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteChannel", "app.webhooks.permanent_delete_incoming_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Webhook().PermanentDeleteOutgoingByChannel(channel.Id); err != nil { - return model.NewAppError("PermanentDeleteChannel", "app.webhooks.permanent_delete_outgoing_by_channel.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteChannel", "app.webhooks.permanent_delete_outgoing_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } deleteAt := model.GetMillis() if nErr := a.Srv().Store.Channel().PermanentDelete(channel.Id); nErr != nil { - return model.NewAppError("PermanentDeleteChannel", "app.channel.permanent_delete.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteChannel", "app.channel.permanent_delete.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } a.invalidateCacheForChannel(channel) @@ -3005,7 +3007,7 @@ func (a *App) PermanentDeleteChannel(c request.CTX, channel *model.Channel) *mod func (a *App) RemoveAllDeactivatedMembersFromChannel(c request.CTX, channel *model.Channel) *model.AppError { err := a.Srv().Store.Channel().RemoveAllDeactivatedMembers(channel.Id) if err != nil { - return model.NewAppError("RemoveAllDeactivatedMembersFromChannel", "app.channel.remove_all_deactivated_members.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RemoveAllDeactivatedMembersFromChannel", "app.channel.remove_all_deactivated_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -3051,14 +3053,14 @@ func (a *App) MoveChannel(c request.CTX, team *model.Team, channel *model.Channe var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return model.NewAppError("MoveChannel", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("MoveChannel", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return model.NewAppError("MoveChannel", "app.team.get.finding.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("MoveChannel", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } if nErr := a.Srv().Store.Channel().UpdateSidebarChannelCategoryOnMove(channel, team.Id); nErr != nil { - return model.NewAppError("MoveChannel", "app.channel.sidebar_categories.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("MoveChannel", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } channel.TeamId = team.Id @@ -3067,11 +3069,11 @@ func (a *App) MoveChannel(c request.CTX, team *model.Team, channel *model.Channe var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return model.NewAppError("MoveChannel", "app.channel.update.bad_id", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("MoveChannel", "app.channel.update.bad_id", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): return appErr default: - return model.NewAppError("MoveChannel", "app.channel.update_channel.internal_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("MoveChannel", "app.channel.update_channel.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -3127,7 +3129,7 @@ func (a *App) postChannelMoveMessage(c request.CTX, user *model.User, channel *m } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("postChannelMoveMessage", "api.team.move_channel.post.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postChannelMoveMessage", "api.team.move_channel.post.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -3175,7 +3177,7 @@ func (a *App) RemoveUsersFromChannelNotMemberOfTeam(c request.CTX, remover *mode func (a *App) GetPinnedPosts(c request.CTX, channelID string) (*model.PostList, *model.AppError) { posts, err := a.Srv().Store.Channel().GetPinnedPosts(channelID) if err != nil { - return nil, model.NewAppError("GetPinnedPosts", "app.channel.pinned_posts.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPinnedPosts", "app.channel.pinned_posts.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if appErr := a.filterInaccessiblePosts(posts, filterPostOptions{assumeSortedCreatedAt: true}); appErr != nil { @@ -3194,9 +3196,9 @@ func (a *App) ToggleMuteChannel(c request.CTX, channelID, userID string) (*model case errors.As(nErr, &appErr): return nil, appErr case errors.As(nErr, &nfErr): - return nil, model.NewAppError("ToggleMuteChannel", MissingChannelMemberError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("ToggleMuteChannel", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("ToggleMuteChannel", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ToggleMuteChannel", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -3248,7 +3250,7 @@ func (a *App) setChannelsMuted(c request.CTX, channelIDs []string, userID string case errors.As(err, &appErr): return nil, appErr case errors.As(err, &nfErr): - return nil, model.NewAppError("setChannelsMuted", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(nfErr) + return nil, model.NewAppError("setChannelsMuted", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(err) default: return nil, model.NewAppError("setChannelsMuted", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } @@ -3401,7 +3403,7 @@ func (s *Server) getDirectChannel(c request.CTX, userID, otherUserID string) (*m return nil, nil } - return nil, model.NewAppError("GetOrCreateDirectChannel", "web.incoming_webhook.channel.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetOrCreateDirectChannel", "web.incoming_webhook.channel.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return channel, nil @@ -3414,7 +3416,7 @@ func (a *App) GetTopChannelsForTeamSince(c request.CTX, teamID, userID string, o topChannels, err := a.Srv().Store.Channel().GetTopChannelsForTeamSince(teamID, userID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage) if err != nil { - return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.channel.get_top_for_team_since.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.channel.get_top_for_team_since.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topChannels, nil } @@ -3426,7 +3428,7 @@ func (a *App) GetTopChannelsForUserSince(c request.CTX, userID, teamID string, o topChannels, err := a.Srv().Store.Channel().GetTopChannelsForUserSince(userID, teamID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage) if err != nil { - return nil, model.NewAppError("GetTopChannelsForUserSince", "app.channel.get_top_for_user_since.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTopChannelsForUserSince", "app.channel.get_top_for_user_since.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topChannels, nil } @@ -3442,7 +3444,7 @@ func (a *App) PostCountsByDuration(c request.CTX, channelIDs []string, sinceUnix } postCountByDay, err := a.Srv().Store.Channel().PostCountsByDuration(channelIDs, sinceUnixMillis, userID, grouping, groupingLocation) if err != nil { - return nil, model.NewAppError("PostCountsByDuration", "app.channel.get_post_count_by_day.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("PostCountsByDuration", "app.channel.get_post_count_by_day.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return postCountByDay, nil } diff --git a/app/channel_category.go b/app/channel_category.go index 972d80cc51..1420935b79 100644 --- a/app/channel_category.go +++ b/app/channel_category.go @@ -17,7 +17,7 @@ import ( func (a *App) createInitialSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError) { categories, nErr := a.Srv().Store.Channel().CreateInitialSidebarCategories(userID, opts) if nErr != nil { - return nil, model.NewAppError("createInitialSidebarCategories", "app.channel.create_initial_sidebar_categories.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createInitialSidebarCategories", "app.channel.create_initial_sidebar_categories.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return categories, nil @@ -41,9 +41,9 @@ func (a *App) GetSidebarCategoriesForTeamForUser(c request.CTX, userID, teamID s var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetSidebarCategoriesForTeamForUser", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetSidebarCategoriesForTeamForUser", "app.channel.sidebar_categories.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetSidebarCategoriesForTeamForUser", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetSidebarCategoriesForTeamForUser", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -65,9 +65,9 @@ func (a *App) GetSidebarCategories(c request.CTX, userID string, opts *store.Sid var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetSidebarCategories", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetSidebarCategories", "app.channel.sidebar_categories.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetSidebarCategories", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetSidebarCategories", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -80,9 +80,9 @@ func (a *App) GetSidebarCategoryOrder(c request.CTX, userID, teamID string) ([]s var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -95,9 +95,9 @@ func (a *App) GetSidebarCategory(c request.CTX, categoryId string) (*model.Sideb var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetSidebarCategory", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetSidebarCategory", "app.channel.sidebar_categories.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetSidebarCategory", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetSidebarCategory", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -110,9 +110,9 @@ func (a *App) CreateSidebarCategory(c request.CTX, userID, teamID string, newCat var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("CreateSidebarCategory", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("CreateSidebarCategory", "app.channel.sidebar_categories.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("CreateSidebarCategory", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateSidebarCategory", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } message := model.NewWebSocketEvent(model.WebsocketEventSidebarCategoryCreated, teamID, "", userID, nil) @@ -128,11 +128,11 @@ func (a *App) UpdateSidebarCategoryOrder(c request.CTX, userID, teamID string, c var invErr *store.ErrInvalidInput switch { case errors.As(err, &nfErr): - return model.NewAppError("UpdateSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("UpdateSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, "", http.StatusNotFound).Wrap(err) case errors.As(err, &invErr): - return model.NewAppError("UpdateSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("UpdateSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return model.NewAppError("UpdateSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdateSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } message := model.NewWebSocketEvent(model.WebsocketEventSidebarCategoryOrderUpdated, teamID, "", userID, nil) @@ -274,9 +274,9 @@ func (a *App) DeleteSidebarCategory(c request.CTX, userID, teamID, categoryId st var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return model.NewAppError("DeleteSidebarCategory", "app.channel.sidebar_categories.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("DeleteSidebarCategory", "app.channel.sidebar_categories.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return model.NewAppError("DeleteSidebarCategory", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteSidebarCategory", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } diff --git a/app/command.go b/app/command.go index 31a3c01554..1f158a15e6 100644 --- a/app/command.go +++ b/app/command.go @@ -101,7 +101,7 @@ func (a *App) ListAutocompleteCommands(teamID string, T i18n.TranslateFunc) ([]* if *a.Config().ServiceSettings.EnableCommands { teamCmds, err := a.Srv().Store.Command().GetByTeam(teamID) if err != nil { - return nil, model.NewAppError("ListAutocompleteCommands", "app.command.listautocompletecommands.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ListAutocompleteCommands", "app.command.listautocompletecommands.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, cmd := range teamCmds { @@ -134,7 +134,7 @@ func (a *App) ListTeamCommands(teamID string) ([]*model.Command, *model.AppError teamCmds, err := a.Srv().Store.Command().GetByTeam(teamID) if err != nil { - return nil, model.NewAppError("ListTeamCommands", "app.command.listteamcommands.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ListTeamCommands", "app.command.listteamcommands.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teamCmds, nil @@ -164,7 +164,7 @@ func (a *App) ListAllCommands(teamID string, T i18n.TranslateFunc) ([]*model.Com if *a.Config().ServiceSettings.EnableCommands { teamCmds, err := a.Srv().Store.Command().GetByTeam(teamID) if err != nil { - return nil, model.NewAppError("ListAllCommands", "app.command.listallcommands.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ListAllCommands", "app.command.listallcommands.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, cmd := range teamCmds { if !seen[cmd.Trigger] { @@ -391,7 +391,7 @@ func (a *App) tryExecuteCustomCommand(c request.CTX, args *model.CommandArgs, tr teamCmds, err := a.Srv().Store.Command().GetByTeam(args.TeamId) if err != nil { - return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.command.tryexecutecustomcommand.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.command.tryexecutecustomcommand.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } tr := <-teamChan @@ -399,9 +399,9 @@ func (a *App) tryExecuteCustomCommand(c request.CTX, args *model.CommandArgs, tr var nfErr *store.ErrNotFound switch { case errors.As(tr.NErr, &nfErr): - return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(tr.NErr) default: - return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.team.get.finding.app_error", nil, tr.NErr.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(tr.NErr) } } team := tr.Data.(*model.Team) @@ -411,9 +411,9 @@ func (a *App) tryExecuteCustomCommand(c request.CTX, args *model.CommandArgs, tr var nfErr *store.ErrNotFound switch { case errors.As(ur.NErr, &nfErr): - return nil, nil, model.NewAppError("tryExecuteCustomCommand", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, model.NewAppError("tryExecuteCustomCommand", MissingAccountError, nil, "", http.StatusNotFound).Wrap(ur.NErr) default: - return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.user.get.app_error", nil, ur.NErr.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(ur.NErr) } } user := ur.Data.(*model.User) @@ -423,9 +423,9 @@ func (a *App) tryExecuteCustomCommand(c request.CTX, args *model.CommandArgs, tr var nfErr *store.ErrNotFound switch { case errors.As(cr.NErr, &nfErr): - return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(cr.NErr) default: - return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.channel.get.find.app_error", nil, cr.NErr.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.channel.get.find.app_error", nil, "", http.StatusInternalServerError).Wrap(cr.NErr) } } channel := cr.Data.(*model.Channel) @@ -473,7 +473,7 @@ func (a *App) tryExecuteCustomCommand(c request.CTX, args *model.CommandArgs, tr hook, appErr := a.CreateCommandWebhook(cmd.Id, args) if appErr != nil { - return cmd, nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]any{"Trigger": trigger}, appErr.Error(), http.StatusInternalServerError) + return cmd, nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]any{"Trigger": trigger}, "", http.StatusInternalServerError).Wrap(appErr) } p.Set("response_url", args.SiteURL+"/hooks/commands/"+hook.Id) @@ -491,7 +491,7 @@ func (a *App) DoCommandRequest(cmd *model.Command, p url.Values) (*model.Command } if err != nil { - return cmd, nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]any{"Trigger": cmd.Trigger}, err.Error(), http.StatusInternalServerError) + return cmd, nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]any{"Trigger": cmd.Trigger}, "", http.StatusInternalServerError).Wrap(err) } if cmd.Method == model.CommandMethodGet { @@ -510,7 +510,7 @@ func (a *App) DoCommandRequest(cmd *model.Command, p url.Values) (*model.Command // Send the request resp, err := a.HTTPService().MakeClient(false).Do(req) if err != nil { - return cmd, nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]any{"Trigger": cmd.Trigger}, err.Error(), http.StatusInternalServerError) + return cmd, nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]any{"Trigger": cmd.Trigger}, "", http.StatusInternalServerError).Wrap(err) } defer resp.Body.Close() @@ -527,7 +527,7 @@ func (a *App) DoCommandRequest(cmd *model.Command, p url.Values) (*model.Command response, err := model.CommandResponseFromHTTPBody(resp.Header.Get("Content-Type"), body) if err != nil { - return cmd, nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]any{"Trigger": cmd.Trigger}, err.Error(), http.StatusInternalServerError) + return cmd, nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]any{"Trigger": cmd.Trigger}, "", http.StatusInternalServerError).Wrap(err) } else if response == nil { return cmd, nil, model.NewAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]any{"Trigger": cmd.Trigger}, "", http.StatusInternalServerError) } @@ -580,7 +580,7 @@ func (a *App) HandleCommandResponsePost(c request.CTX, command *model.Command, a if response.ChannelId != "" { _, err := a.GetChannelMember(c, response.ChannelId, args.UserId) if err != nil { - err = model.NewAppError("HandleCommandResponsePost", "api.command.command_post.forbidden.app_error", nil, err.Error(), http.StatusForbidden) + err = model.NewAppError("HandleCommandResponsePost", "api.command.command_post.forbidden.app_error", nil, "", http.StatusForbidden).Wrap(err) return nil, err } post.ChannelId = response.ChannelId @@ -640,7 +640,7 @@ func (a *App) createCommand(cmd *model.Command) (*model.Command, *model.AppError teamCmds, err := a.Srv().Store.Command().GetByTeam(cmd.TeamId) if err != nil { - return nil, model.NewAppError("CreateCommand", "app.command.createcommand.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateCommand", "app.command.createcommand.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, existingCommand := range teamCmds { @@ -663,7 +663,7 @@ func (a *App) createCommand(cmd *model.Command) (*model.Command, *model.AppError case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("CreateCommand", "app.command.createcommand.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateCommand", "app.command.createcommand.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -680,9 +680,9 @@ func (a *App) GetCommand(commandID string) (*model.Command, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("SqlCommandStore.Get", "store.sql_command.get.missing.app_error", map[string]any{"command_id": commandID}, "", http.StatusNotFound) + return nil, model.NewAppError("SqlCommandStore.Get", "store.sql_command.get.missing.app_error", map[string]any{"command_id": commandID}, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetCommand", "app.command.getcommand.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetCommand", "app.command.getcommand.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return command, nil @@ -709,11 +709,11 @@ func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, var appErr *model.AppError switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("SqlCommandStore.Update", "store.sql_command.update.missing.app_error", map[string]any{"command_id": updatedCmd.Id}, "", http.StatusNotFound) + return nil, model.NewAppError("SqlCommandStore.Update", "store.sql_command.update.missing.app_error", map[string]any{"command_id": updatedCmd.Id}, "", http.StatusNotFound).Wrap(err) case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("UpdateCommand", "app.command.updatecommand.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateCommand", "app.command.updatecommand.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -729,11 +729,11 @@ func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppEr var appErr *model.AppError switch { case errors.As(err, &nfErr): - return model.NewAppError("SqlCommandStore.Update", "store.sql_command.update.missing.app_error", map[string]any{"command_id": command.Id}, "", http.StatusNotFound) + return model.NewAppError("SqlCommandStore.Update", "store.sql_command.update.missing.app_error", map[string]any{"command_id": command.Id}, "", http.StatusNotFound).Wrap(err) case errors.As(err, &appErr): return appErr default: - return model.NewAppError("MoveCommand", "app.command.movecommand.internal_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("MoveCommand", "app.command.movecommand.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -753,11 +753,11 @@ func (a *App) RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppE var appErr *model.AppError switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("SqlCommandStore.Update", "store.sql_command.update.missing.app_error", map[string]any{"command_id": cmd.Id}, "", http.StatusNotFound) + return nil, model.NewAppError("SqlCommandStore.Update", "store.sql_command.update.missing.app_error", map[string]any{"command_id": cmd.Id}, "", http.StatusNotFound).Wrap(err) case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("RegenCommandToken", "app.command.regencommandtoken.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("RegenCommandToken", "app.command.regencommandtoken.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -771,7 +771,7 @@ func (a *App) DeleteCommand(commandID string) *model.AppError { err := a.Srv().Store.Command().Delete(commandID, model.GetMillis()) if err != nil { - return model.NewAppError("DeleteCommand", "app.command.deletecommand.internal_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteCommand", "app.command.deletecommand.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil diff --git a/app/compliance.go b/app/compliance.go index 0a398c6693..b1da64e8d6 100644 --- a/app/compliance.go +++ b/app/compliance.go @@ -20,7 +20,7 @@ func (a *App) GetComplianceReports(page, perPage int) (model.Compliances, *model compliances, err := a.Srv().Store.Compliance().GetAll(page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetComplianceReports", "app.compliance.get.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetComplianceReports", "app.compliance.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return compliances, nil @@ -40,7 +40,7 @@ func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *m case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("SaveComplianceReport", "app.compliance.save.saving.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SaveComplianceReport", "app.compliance.save.saving.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -65,9 +65,9 @@ func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.Ap var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetComplianceReport", "app.compliance.get.finding.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetComplianceReport", "app.compliance.get.finding.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetComplianceReport", "app.compliance.get.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetComplianceReport", "app.compliance.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -77,7 +77,7 @@ func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.Ap func (a *App) GetComplianceFile(job *model.Compliance) ([]byte, *model.AppError) { f, err := os.ReadFile(*a.Config().ComplianceSettings.Directory + "compliance/" + job.JobName() + ".zip") if err != nil { - return nil, model.NewAppError("readFile", "api.file.read_file.reading_local.app_error", nil, err.Error(), http.StatusNotImplemented) + return nil, model.NewAppError("readFile", "api.file.read_file.reading_local.app_error", nil, "", http.StatusNotImplemented).Wrap(err) } return f, nil } diff --git a/app/email/email.go b/app/email/email.go index 27153de375..10c3ce0d9f 100644 --- a/app/email/email.go +++ b/app/email/email.go @@ -820,7 +820,7 @@ func (es *Service) SendMailWithEmbeddedFiles(to, subject, htmlBody string, embed func (es *Service) InvalidateVerifyEmailTokensForUser(userID string) *model.AppError { tokens, err := es.store.Token().GetAllTokensByType(TokenTypeVerifyEmail) if err != nil { - return model.NewAppError("InvalidateVerifyEmailTokensForUser", "api.user.invalidate_verify_email_tokens.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("InvalidateVerifyEmailTokensForUser", "api.user.invalidate_verify_email_tokens.error", nil, "", http.StatusInternalServerError).Wrap(err) } var appErr *model.AppError = nil @@ -830,7 +830,7 @@ func (es *Service) InvalidateVerifyEmailTokensForUser(userID string) *model.AppE Email string }{} if err := json.Unmarshal([]byte(token.Extra), &tokenExtra); err != nil { - appErr = model.NewAppError("InvalidateVerifyEmailTokensForUser", "api.user.invalidate_verify_email_tokens_parse.error", nil, err.Error(), http.StatusInternalServerError) + appErr = model.NewAppError("InvalidateVerifyEmailTokensForUser", "api.user.invalidate_verify_email_tokens_parse.error", nil, "", http.StatusInternalServerError).Wrap(err) continue } @@ -839,7 +839,7 @@ func (es *Service) InvalidateVerifyEmailTokensForUser(userID string) *model.AppE } if err := es.store.Token().Delete(token.Token); err != nil { - appErr = model.NewAppError("InvalidateVerifyEmailTokensForUser", "api.user.invalidate_verify_email_tokens_delete.error", nil, err.Error(), http.StatusInternalServerError) + appErr = model.NewAppError("InvalidateVerifyEmailTokensForUser", "api.user.invalidate_verify_email_tokens_delete.error", nil, "", http.StatusInternalServerError).Wrap(err) } } diff --git a/app/emoji.go b/app/emoji.go index 5653ecacbc..930abb8fa5 100644 --- a/app/emoji.go +++ b/app/emoji.go @@ -91,7 +91,7 @@ func (a *App) CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartIma func (a *App) GetEmojiList(page, perPage int, sort string) ([]*model.Emoji, *model.AppError) { list, err := a.Srv().Store.Emoji().GetList(page*perPage, perPage, sort) if err != nil { - return nil, model.NewAppError("GetEmojiList", "app.emoji.get_list.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetEmojiList", "app.emoji.get_list.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, nil @@ -108,7 +108,7 @@ func (a *App) UploadEmojiImage(id string, imageData *multipart.FileHeader) *mode file, err := imageData.Open() if err != nil { - return model.NewAppError("uploadEmojiImage", "api.emoji.upload.open.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("uploadEmojiImage", "api.emoji.upload.open.app_error", nil, "", http.StatusBadRequest).Wrap(err) } defer file.Close() @@ -118,7 +118,7 @@ func (a *App) UploadEmojiImage(id string, imageData *multipart.FileHeader) *mode // make sure the file is an image and is within the required dimensions config, _, err := image.DecodeConfig(bytes.NewReader(buf.Bytes())) if err != nil { - return model.NewAppError("uploadEmojiImage", "api.emoji.upload.image.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("uploadEmojiImage", "api.emoji.upload.image.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if config.Width > MaxEmojiOriginalWidth || config.Height > MaxEmojiOriginalHeight { @@ -139,24 +139,24 @@ func (a *App) UploadEmojiImage(id string, imageData *multipart.FileHeader) *mode if info.MimeType == "image/gif" { gif_data, err := gif.DecodeAll(bytes.NewReader(data)) if err != nil { - return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.gif_decode_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.gif_decode_error", nil, "", http.StatusBadRequest).Wrap(err) } resized_gif := resizeEmojiGif(gif_data) if err := gif.EncodeAll(newbuf, resized_gif); err != nil { - return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.gif_encode_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.gif_encode_error", nil, "", http.StatusBadRequest).Wrap(err) } buf = newbuf } else { img, _, err := image.Decode(bytes.NewReader(data)) if err != nil { - return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.decode_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.decode_error", nil, "", http.StatusBadRequest).Wrap(err) } resized_image := resizeEmoji(img, config.Width, config.Height) if err := png.Encode(newbuf, resized_image); err != nil { - return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.encode_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.encode_error", nil, "", http.StatusBadRequest).Wrap(err) } buf = newbuf } @@ -171,9 +171,9 @@ func (a *App) DeleteEmoji(emoji *model.Emoji) *model.AppError { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return model.NewAppError("DeleteEmoji", "app.emoji.delete.no_results", nil, "id="+emoji.Id+", err="+err.Error(), http.StatusNotFound) + return model.NewAppError("DeleteEmoji", "app.emoji.delete.no_results", nil, "id="+emoji.Id, http.StatusNotFound).Wrap(err) default: - return model.NewAppError("DeleteEmoji", "app.emoji.delete.app_error", nil, "id="+emoji.Id+", err="+err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteEmoji", "app.emoji.delete.app_error", nil, "id="+emoji.Id, http.StatusInternalServerError).Wrap(err) } } @@ -196,9 +196,9 @@ func (a *App) GetEmoji(emojiId string) (*model.Emoji, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return emoji, model.NewAppError("GetEmoji", "app.emoji.get.no_result", nil, err.Error(), http.StatusNotFound) + return emoji, model.NewAppError("GetEmoji", "app.emoji.get.no_result", nil, "", http.StatusNotFound).Wrap(err) default: - return emoji, model.NewAppError("GetEmoji", "app.emoji.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return emoji, model.NewAppError("GetEmoji", "app.emoji.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -219,9 +219,9 @@ func (a *App) GetEmojiByName(emojiName string) (*model.Emoji, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return emoji, model.NewAppError("GetEmojiByName", "app.emoji.get_by_name.no_result", nil, err.Error(), http.StatusNotFound) + return emoji, model.NewAppError("GetEmojiByName", "app.emoji.get_by_name.no_result", nil, "", http.StatusNotFound).Wrap(err) default: - return emoji, model.NewAppError("GetEmojiByName", "app.emoji.get_by_name.app_error", nil, err.Error(), http.StatusInternalServerError) + return emoji, model.NewAppError("GetEmojiByName", "app.emoji.get_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -247,20 +247,20 @@ func (a *App) GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(storeErr, &nfErr): - return nil, "", model.NewAppError("GetEmojiImage", "app.emoji.get.no_result", nil, storeErr.Error(), http.StatusNotFound) + return nil, "", model.NewAppError("GetEmojiImage", "app.emoji.get.no_result", nil, "", http.StatusNotFound).Wrap(storeErr) default: - return nil, "", model.NewAppError("GetEmojiImage", "app.emoji.get.app_error", nil, storeErr.Error(), http.StatusInternalServerError) + return nil, "", model.NewAppError("GetEmojiImage", "app.emoji.get.app_error", nil, "", http.StatusInternalServerError).Wrap(storeErr) } } img, appErr := a.ReadFile(getEmojiImagePath(emojiId)) if appErr != nil { - return nil, "", model.NewAppError("getEmojiImage", "api.emoji.get_image.read.app_error", nil, appErr.Error(), http.StatusNotFound) + return nil, "", model.NewAppError("getEmojiImage", "api.emoji.get_image.read.app_error", nil, "", http.StatusNotFound).Wrap(appErr) } _, imageType, err := image.DecodeConfig(bytes.NewReader(img)) if err != nil { - return nil, "", model.NewAppError("getEmojiImage", "api.emoji.get_image.decode.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, "", model.NewAppError("getEmojiImage", "api.emoji.get_image.decode.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return img, imageType, nil @@ -295,9 +295,9 @@ func (a *App) GetEmojiStaticURL(emojiName string) (string, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return "", model.NewAppError("GetEmojiStaticURL", "app.emoji.get_by_name.no_result", nil, err.Error(), http.StatusNotFound) + return "", model.NewAppError("GetEmojiStaticURL", "app.emoji.get_by_name.no_result", nil, "", http.StatusNotFound).Wrap(err) default: - return "", model.NewAppError("GetEmojiStaticURL", "app.emoji.get_by_name.app_error", nil, err.Error(), http.StatusInternalServerError) + return "", model.NewAppError("GetEmojiStaticURL", "app.emoji.get_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } diff --git a/app/expirynotify.go b/app/expirynotify.go index 0f5c813ced..a10f3f0fe5 100644 --- a/app/expirynotify.go +++ b/app/expirynotify.go @@ -24,7 +24,7 @@ func (a *App) NotifySessionsExpired() error { // Get all mobile sessions that expired within the last hour. sessions, err := a.ch.srv.Store.Session().GetSessionsExpired(OneHourMillis, true, true) if err != nil { - return model.NewAppError("NotifySessionsExpired", "app.session.analytics_session_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("NotifySessionsExpired", "app.session.analytics_session_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } msg := &model.PushNotification{ diff --git a/app/export.go b/app/export.go index 553e1d41b7..b45950cbee 100644 --- a/app/export.go +++ b/app/export.go @@ -170,7 +170,7 @@ func (a *App) exportAllTeams(writer io.Writer) (map[string]bool, *model.AppError for { teams, err := a.Srv().Store.Team().GetAllForExportAfter(1000, afterId) if err != nil { - return nil, model.NewAppError("exportAllTeams", "app.team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("exportAllTeams", "app.team.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(teams) == 0 { @@ -202,7 +202,7 @@ func (a *App) exportAllChannels(writer io.Writer, teamNames map[string]bool) *mo channels, err := a.Srv().Store.Channel().GetAllChannelsForExportAfter(1000, afterId) if err != nil { - return model.NewAppError("exportAllChannels", "app.channel.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("exportAllChannels", "app.channel.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(channels) == 0 { @@ -237,7 +237,7 @@ func (a *App) exportAllUsers(writer io.Writer) *model.AppError { users, err := a.Srv().Store.User().GetAllAfter(1000, afterId) if err != nil { - return model.NewAppError("exportAllUsers", "app.user.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("exportAllUsers", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(users) == 0 { @@ -312,7 +312,7 @@ func (a *App) buildUserTeamAndChannelMemberships(userID string) (*[]UserTeamImpo members, err := a.Srv().Store.Team().GetTeamMembersForExport(userID) if err != nil { - return nil, model.NewAppError("buildUserTeamAndChannelMemberships", "app.team.get_members.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("buildUserTeamAndChannelMemberships", "app.team.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, member := range members { @@ -348,7 +348,7 @@ func (a *App) buildUserChannelMemberships(userID string, teamID string) (*[]User members, nErr := a.Srv().Store.Channel().GetChannelMembersForExport(userID, teamID) if nErr != nil { - return nil, model.NewAppError("buildUserChannelMemberships", "app.channel.get_members.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("buildUserChannelMemberships", "app.channel.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } category := model.PreferenceCategoryFavoriteChannel @@ -391,7 +391,7 @@ func (a *App) exportAllPosts(ctx request.CTX, writer io.Writer, withAttachments for { posts, nErr := a.Srv().Store.Post().GetParentsForExportAfter(1000, afterId) if nErr != nil { - return nil, model.NewAppError("exportAllPosts", "app.post.get_posts.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("exportAllPosts", "app.post.get_posts.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } if len(posts) == 0 { @@ -451,7 +451,7 @@ func (a *App) buildPostReplies(ctx request.CTX, postID string, withAttachments b replyPosts, nErr := a.Srv().Store.Post().GetRepliesForExport(postID) if nErr != nil { - return nil, nil, model.NewAppError("buildPostReplies", "app.post.get_posts.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("buildPostReplies", "app.post.get_posts.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } for _, reply := range replyPosts { @@ -485,7 +485,7 @@ func (a *App) BuildPostReactions(ctx request.CTX, postID string) (*[]ReactionImp reactions, nErr := a.Srv().Store.Reaction().GetForPost(postID, true) if nErr != nil { - return nil, model.NewAppError("BuildPostReactions", "app.reaction.get_for_post.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("BuildPostReactions", "app.reaction.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } for _, reaction := range reactions { @@ -496,7 +496,7 @@ func (a *App) BuildPostReactions(ctx request.CTX, postID string) (*[]ReactionImp ctx.Logger().Info("Skipping reactions by user since the entity doesn't exist anymore", mlog.String("user_id", reaction.UserId)) continue } - return nil, model.NewAppError("BuildPostReactions", "app.user.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("BuildPostReactions", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } reactionsOfPost = append(reactionsOfPost, *ImportReactionFromPost(user, reaction)) } @@ -508,7 +508,7 @@ func (a *App) BuildPostReactions(ctx request.CTX, postID string) (*[]ReactionImp func (a *App) buildPostAttachments(postID string) ([]AttachmentImportData, *model.AppError) { infos, nErr := a.Srv().Store.FileInfo().GetForPost(postID, false, false, false) if nErr != nil { - return nil, model.NewAppError("buildPostAttachments", "app.file_info.get_for_post.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("buildPostAttachments", "app.file_info.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } attachments := make([]AttachmentImportData, 0, len(infos)) @@ -605,7 +605,7 @@ func (a *App) exportAllDirectChannels(writer io.Writer) *model.AppError { for { channels, err := a.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, afterId) if err != nil { - return model.NewAppError("exportAllDirectChannels", "app.channel.get_all_direct.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("exportAllDirectChannels", "app.channel.get_all_direct.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(channels) == 0 { @@ -641,7 +641,7 @@ func (a *App) exportAllDirectPosts(ctx request.CTX, writer io.Writer, withAttach for { posts, err := a.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, afterId) if err != nil { - return nil, model.NewAppError("exportAllDirectPosts", "app.post.get_direct_posts.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("exportAllDirectPosts", "app.post.get_direct_posts.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(posts) == 0 { diff --git a/app/file.go b/app/file.go index 430038e0dd..a446a1d9d7 100644 --- a/app/file.go +++ b/app/file.go @@ -67,7 +67,7 @@ func (a *App) CheckMandatoryS3Fields(settings *model.FileSettings) *model.AppErr fileBackendSettings := settings.ToFileBackendSettings(false, false) err := fileBackendSettings.CheckMandatoryS3Fields() if err != nil { - return model.NewAppError("CheckMandatoryS3Fields", "api.admin.test_s3.missing_s3_bucket", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("CheckMandatoryS3Fields", "api.admin.test_s3.missing_s3_bucket", nil, "", http.StatusBadRequest).Wrap(err) } return nil } @@ -75,11 +75,11 @@ func (a *App) CheckMandatoryS3Fields(settings *model.FileSettings) *model.AppErr func connectionTestErrorToAppError(connTestErr error) *model.AppError { switch err := connTestErr.(type) { case *filestore.S3FileBackendAuthError: - return model.NewAppError("TestConnection", "api.file.test_connection_s3_auth.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("TestConnection", "api.file.test_connection_s3_auth.app_error", nil, "", http.StatusInternalServerError).Wrap(err) case *filestore.S3FileBackendNoBucketError: - return model.NewAppError("TestConnection", "api.file.test_connection_s3_bucket_does_not_exist.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("TestConnection", "api.file.test_connection_s3_bucket_does_not_exist.app_error", nil, "", http.StatusInternalServerError).Wrap(err) default: - return model.NewAppError("TestConnection", "api.file.test_connection.app_error", nil, connTestErr.Error(), http.StatusInternalServerError) + return model.NewAppError("TestConnection", "api.file.test_connection.app_error", nil, "", http.StatusInternalServerError).Wrap(connTestErr) } } @@ -96,7 +96,7 @@ func (a *App) TestFileStoreConnectionWithConfig(cfg *model.FileSettings) *model. insecure := a.Config().ServiceSettings.EnableInsecureOutgoingConnections backend, err := filestore.NewFileBackend(cfg.ToFileBackendSettings(license != nil && *license.Features.Compliance, insecure != nil && *insecure)) if err != nil { - return model.NewAppError("FileBackend", "api.file.no_driver.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("FileBackend", "api.file.no_driver.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } nErr := backend.TestConnection() if nErr != nil { @@ -112,7 +112,7 @@ func (a *App) ReadFile(path string) ([]byte, *model.AppError) { func (s *Server) fileReader(path string) (filestore.ReadCloseSeeker, *model.AppError) { result, nErr := s.FileBackend().Reader(path) if nErr != nil { - return nil, model.NewAppError("FileReader", "api.file.file_reader.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("FileReader", "api.file.file_reader.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return result, nil } @@ -129,7 +129,7 @@ func (a *App) FileExists(path string) (bool, *model.AppError) { func (s *Server) fileExists(path string) (bool, *model.AppError) { result, nErr := s.FileBackend().FileExists(path) if nErr != nil { - return false, model.NewAppError("FileExists", "api.file.file_exists.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return false, model.NewAppError("FileExists", "api.file.file_exists.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return result, nil } @@ -137,7 +137,7 @@ func (s *Server) fileExists(path string) (bool, *model.AppError) { func (a *App) FileSize(path string) (int64, *model.AppError) { size, nErr := a.FileBackend().FileSize(path) if nErr != nil { - return 0, model.NewAppError("FileSize", "api.file.file_size.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("FileSize", "api.file.file_size.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return size, nil } @@ -145,7 +145,7 @@ func (a *App) FileSize(path string) (int64, *model.AppError) { func (a *App) FileModTime(path string) (time.Time, *model.AppError) { modTime, nErr := a.FileBackend().FileModTime(path) if nErr != nil { - return time.Time{}, model.NewAppError("FileModTime", "api.file.file_mod_time.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return time.Time{}, model.NewAppError("FileModTime", "api.file.file_mod_time.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return modTime, nil @@ -154,7 +154,7 @@ func (a *App) FileModTime(path string) (time.Time, *model.AppError) { func (a *App) MoveFile(oldPath, newPath string) *model.AppError { nErr := a.FileBackend().MoveFile(oldPath, newPath) if nErr != nil { - return model.NewAppError("MoveFile", "api.file.move_file.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("MoveFile", "api.file.move_file.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return nil } @@ -166,7 +166,7 @@ func (a *App) WriteFile(fr io.Reader, path string) (int64, *model.AppError) { func (s *Server) writeFile(fr io.Reader, path string) (int64, *model.AppError) { result, nErr := s.FileBackend().WriteFile(fr, path) if nErr != nil { - return result, model.NewAppError("WriteFile", "api.file.write_file.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return result, model.NewAppError("WriteFile", "api.file.write_file.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return result, nil } @@ -174,7 +174,7 @@ func (s *Server) writeFile(fr io.Reader, path string) (int64, *model.AppError) { func (a *App) AppendFile(fr io.Reader, path string) (int64, *model.AppError) { result, nErr := a.FileBackend().AppendFile(fr, path) if nErr != nil { - return result, model.NewAppError("AppendFile", "api.file.append_file.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return result, model.NewAppError("AppendFile", "api.file.append_file.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return result, nil } @@ -186,7 +186,7 @@ func (a *App) RemoveFile(path string) *model.AppError { func (s *Server) removeFile(path string) *model.AppError { nErr := s.FileBackend().RemoveFile(path) if nErr != nil { - return model.NewAppError("RemoveFile", "api.file.remove_file.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("RemoveFile", "api.file.remove_file.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return nil } @@ -211,7 +211,7 @@ func (s *Server) listDirectory(path string, recursion bool) ([]string, *model.Ap } if nErr != nil { - return nil, model.NewAppError("ListDirectory", "api.file.list_directory.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ListDirectory", "api.file.list_directory.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return paths, nil @@ -220,7 +220,7 @@ func (s *Server) listDirectory(path string, recursion bool) ([]string, *model.Ap func (a *App) RemoveDirectory(path string) *model.AppError { nErr := a.FileBackend().RemoveDirectory(path) if nErr != nil { - return model.NewAppError("RemoveDirectory", "api.file.remove_directory.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("RemoveDirectory", "api.file.remove_directory.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return nil @@ -676,7 +676,7 @@ func (a *App) UploadFileX(c *request.Context, channelID, name string, input io.R case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("UploadFileX", "app.file_info.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UploadFileX", "app.file_info.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -882,7 +882,7 @@ func (a *App) DoUploadFileExpectModification(c request.CTX, now time.Time, rawTe if info.IsImage() && !info.IsSvg() { if limitErr := checkImageResolutionLimit(info.Width, info.Height, *a.Config().FileSettings.MaxImageResolution); limitErr != nil { - err := model.NewAppError("uploadFile", "api.file.upload_file.large_image.app_error", map[string]any{"Filename": filename}, limitErr.Error(), http.StatusBadRequest) + err := model.NewAppError("uploadFile", "api.file.upload_file.large_image.app_error", map[string]any{"Filename": filename}, "", http.StatusBadRequest).Wrap(limitErr) return nil, data, err } @@ -926,7 +926,7 @@ func (a *App) DoUploadFileExpectModification(c request.CTX, now time.Time, rawTe case errors.As(err, &appErr): return nil, data, appErr default: - return nil, data, model.NewAppError("DoUploadFileExpectModification", "app.file_info.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, data, model.NewAppError("DoUploadFileExpectModification", "app.file_info.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1073,9 +1073,9 @@ func (s *Server) getFileInfo(fileID string) (*model.FileInfo, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetFileInfo", "app.file_info.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetFileInfo", "app.file_info.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetFileInfo", "app.file_info.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetFileInfo", "app.file_info.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return fileInfo, nil @@ -1096,11 +1096,11 @@ func (a *App) GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([ var ltErr *store.ErrLimitExceeded switch { case errors.As(err, &invErr): - return nil, model.NewAppError("GetFileInfos", "app.file_info.get_with_options.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetFileInfos", "app.file_info.get_with_options.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, <Err): - return nil, model.NewAppError("GetFileInfos", "app.file_info.get_with_options.app_error", nil, ltErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetFileInfos", "app.file_info.get_with_options.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("GetFileInfos", "app.file_info.get_with_options.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetFileInfos", "app.file_info.get_with_options.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1134,9 +1134,9 @@ func (a *App) CopyFileInfos(userID string, fileIDs []string) ([]string, *model.A var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("CopyFileInfos", "app.file_info.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("CopyFileInfos", "app.file_info.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("CopyFileInfos", "app.file_info.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CopyFileInfos", "app.file_info.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1152,7 +1152,7 @@ func (a *App) CopyFileInfos(userID string, fileIDs []string) ([]string, *model.A case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("CopyFileInfos", "app.file_info.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CopyFileInfos", "app.file_info.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1248,7 +1248,7 @@ func (a *App) SearchFilesInTeamForUser(c *request.Context, terms string, userId case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("SearchFilesInTeamForUser", "app.post.search.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchFilesInTeamForUser", "app.post.search.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } diff --git a/app/group.go b/app/group.go index 7f44487d5a..c23655e972 100644 --- a/app/group.go +++ b/app/group.go @@ -18,16 +18,16 @@ func (a *App) GetGroup(id string, opts *model.GetGroupOpts) (*model.Group, *mode var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetGroup", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetGroup", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetGroup", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroup", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } } if opts != nil && opts.IncludeMemberCount { memberCount, err := a.Srv().Store.Group().GetMemberCount(id) if err != nil { - return nil, model.NewAppError("GetGroup", "app.member_count", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroup", "app.member_count", nil, "", http.StatusInternalServerError).Wrap(err) } group.MemberCount = model.NewInt(int(memberCount)) } @@ -41,9 +41,9 @@ func (a *App) GetGroupByName(name string, opts model.GroupSearchOpts) (*model.Gr var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetGroupByName", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetGroupByName", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetGroupByName", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroupByName", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -56,9 +56,9 @@ func (a *App) GetGroupByRemoteID(remoteID string, groupSource model.GroupSource) var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetGroupByRemoteID", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetGroupByRemoteID", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetGroupByRemoteID", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroupByRemoteID", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -68,7 +68,7 @@ func (a *App) GetGroupByRemoteID(remoteID string, groupSource model.GroupSource) func (a *App) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) { groups, err := a.Srv().Store.Group().GetAllBySource(groupSource) if err != nil { - return nil, model.NewAppError("GetGroupsBySource", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroupsBySource", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return groups, nil @@ -77,7 +77,7 @@ func (a *App) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, func (a *App) GetGroupsByUserId(userID string) ([]*model.Group, *model.AppError) { groups, err := a.Srv().Store.Group().GetByUser(userID) if err != nil { - return nil, model.NewAppError("GetGroupsByUserId", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroupsByUserId", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return groups, nil @@ -97,9 +97,9 @@ func (a *App) CreateGroup(group *model.Group) (*model.Group, *model.AppError) { case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("CreateGroup", "app.group.id.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateGroup", "app.group.id.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("CreateGroup", "app.insert_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateGroup", "app.insert_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -113,7 +113,7 @@ func (a *App) isUniqueToUsernames(val string) *model.AppError { var notFoundErr *store.ErrNotFound user, err := a.Srv().Store.User().GetByUsername(val) if err != nil && !errors.As(err, ¬FoundErr) { - return model.NewAppError("", "app.group.get_by_username_failure", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("", "app.group.get_by_username_failure", nil, "", http.StatusInternalServerError).Wrap(err) } if user != nil { return model.NewAppError("", "app.group.username_conflict", nil, "", http.StatusBadRequest) @@ -136,9 +136,9 @@ func (a *App) CreateGroupWithUserIds(group *model.GroupWithUserIds) (*model.Grou case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("CreateGroupWithUserIds", "app.group.id.app_error", nil, "", http.StatusBadRequest).Wrap(invErr) + return nil, model.NewAppError("CreateGroupWithUserIds", "app.group.id.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &dupKey): - return nil, model.NewAppError("CreateGroupWithUserIds", "app.custom_group.unique_name", nil, "", http.StatusBadRequest).Wrap(dupKey) + return nil, model.NewAppError("CreateGroupWithUserIds", "app.custom_group.unique_name", nil, "", http.StatusBadRequest).Wrap(err) default: return nil, model.NewAppError("CreateGroupWithUserIds", "app.insert_error", nil, "", http.StatusInternalServerError).Wrap(err) } @@ -175,9 +175,9 @@ func (a *App) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) { case errors.As(err, &appErr): return nil, appErr case errors.As(err, &nfErr): - return nil, model.NewAppError("UpdateGroup", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(nfErr) + return nil, model.NewAppError("UpdateGroup", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(err) case errors.As(err, &dupKey): - return nil, model.NewAppError("CreateGroup", "app.custom_group.unique_name", nil, "", http.StatusBadRequest).Wrap(dupKey) + return nil, model.NewAppError("CreateGroup", "app.custom_group.unique_name", nil, "", http.StatusBadRequest).Wrap(err) default: return nil, model.NewAppError("UpdateGroup", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } @@ -207,9 +207,9 @@ func (a *App) DeleteGroup(groupID string) (*model.Group, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("DeleteGroup", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("DeleteGroup", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("DeleteGroup", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("DeleteGroup", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -219,7 +219,7 @@ func (a *App) DeleteGroup(groupID string) (*model.Group, *model.AppError) { func (a *App) GetGroupMemberCount(groupID string) (int64, *model.AppError) { count, err := a.Srv().Store.Group().GetMemberCount(groupID) if err != nil { - return 0, model.NewAppError("GetGroupMemberCount", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("GetGroupMemberCount", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return count, nil @@ -228,7 +228,7 @@ func (a *App) GetGroupMemberCount(groupID string) (int64, *model.AppError) { func (a *App) GetGroupMemberUsers(groupID string) ([]*model.User, *model.AppError) { users, err := a.Srv().Store.Group().GetMemberUsers(groupID) if err != nil { - return nil, model.NewAppError("GetGroupMemberUsers", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroupMemberUsers", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -237,7 +237,7 @@ func (a *App) GetGroupMemberUsers(groupID string) ([]*model.User, *model.AppErro func (a *App) GetGroupMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, int, *model.AppError) { members, err := a.Srv().Store.Group().GetMemberUsersPage(groupID, page, perPage) if err != nil { - return nil, 0, model.NewAppError("GetGroupMemberUsersPage", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("GetGroupMemberUsersPage", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } count, appErr := a.GetGroupMemberCount(groupID) @@ -249,7 +249,7 @@ func (a *App) GetGroupMemberUsersPage(groupID string, page int, perPage int) ([] func (a *App) GetUsersNotInGroupPage(groupID string, page int, perPage int) ([]*model.User, *model.AppError) { members, err := a.Srv().Store.Group().GetNonMemberUsersPage(groupID, page, perPage) if err != nil { - return nil, model.NewAppError("GetUsersNotInGroupPage", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersNotInGroupPage", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return a.sanitizeProfiles(members, false), nil @@ -264,9 +264,9 @@ func (a *App) UpsertGroupMember(groupID string, userID string) (*model.GroupMemb case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("UpsertGroupMember", "app.group.uniqueness_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpsertGroupMember", "app.group.uniqueness_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("UpsertGroupMember", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpsertGroupMember", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -283,9 +283,9 @@ func (a *App) DeleteGroupMember(groupID string, userID string) (*model.GroupMemb var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("DeleteGroupMember", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("DeleteGroupMember", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("DeleteGroupMember", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("DeleteGroupMember", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -300,7 +300,7 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr gs, err := a.Srv().Store.Group().GetGroupSyncable(groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type) var notFoundErr *store.ErrNotFound if err != nil && !errors.As(err, ¬FoundErr) { - return nil, model.NewAppError("UpsertGroupSyncable", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpsertGroupSyncable", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } // reject the syncable creation if the group isn't already associated to the parent team @@ -310,9 +310,9 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("UpsertGroupSyncable", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("UpsertGroupSyncable", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("UpsertGroupSyncable", "app.channel.get.find.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpsertGroupSyncable", "app.channel.get.find.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -322,16 +322,16 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("UpsertGroupSyncable", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("UpsertGroupSyncable", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("UpsertGroupSyncable", "app.team.get.finding.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpsertGroupSyncable", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } if team.IsGroupConstrained() { var teamGroups []*model.GroupWithSchemeAdmin teamGroups, err = a.Srv().Store.Group().GetGroupsByTeam(channel.TeamId, model.GroupSearchOpts{}) if err != nil { - return nil, model.NewAppError("UpsertGroupSyncable", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpsertGroupSyncable", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } var permittedGroup bool for _, teamGroup := range teamGroups { @@ -360,9 +360,9 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr case errors.As(err, &appErr): return nil, appErr case errors.As(err, &nfErr): - return nil, model.NewAppError("UpsertGroupSyncable", "store.sql_channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("UpsertGroupSyncable", "store.sql_channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("UpsertGroupSyncable", "app.insert_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpsertGroupSyncable", "app.insert_error", nil, "", http.StatusInternalServerError).Wrap(err) } } } else { @@ -373,7 +373,7 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("UpsertGroupSyncable", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpsertGroupSyncable", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err) } } } @@ -396,9 +396,9 @@ func (a *App) GetGroupSyncable(groupID string, syncableID string, syncableType m var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetGroupSyncable", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetGroupSyncable", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetGroupSyncable", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroupSyncable", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -408,7 +408,7 @@ func (a *App) GetGroupSyncable(groupID string, syncableID string, syncableType m func (a *App) GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) { groups, err := a.Srv().Store.Group().GetAllGroupSyncablesByGroupId(groupID, syncableType) if err != nil { - return nil, model.NewAppError("GetGroupSyncables", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroupSyncables", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return groups, nil @@ -424,7 +424,7 @@ func (a *App) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("UpdateGroupSyncable", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateGroupSyncable", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -447,11 +447,11 @@ func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableTyp var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("DeleteGroupSyncable", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("DeleteGroupSyncable", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(err) case errors.As(err, &invErr): - return nil, model.NewAppError("DeleteGroupSyncable", "app.group.group_syncable_already_deleted", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("DeleteGroupSyncable", "app.group.group_syncable_already_deleted", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("DeleteGroupSyncable", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("DeleteGroupSyncable", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -459,7 +459,7 @@ func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableTyp if gs.Type == model.GroupSyncableTypeTeam { allGroupChannels, err := a.Srv().Store.Group().GetAllGroupSyncablesByGroupId(gs.GroupId, model.GroupSyncableTypeChannel) if err != nil { - return nil, model.NewAppError("DeleteGroupSyncable", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("DeleteGroupSyncable", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, groupChannel := range allGroupChannels { @@ -469,11 +469,11 @@ func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableTyp var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("DeleteGroupSyncable", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("DeleteGroupSyncable", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(err) case errors.As(err, &invErr): - return nil, model.NewAppError("DeleteGroupSyncable", "app.group.group_syncable_already_deleted", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("DeleteGroupSyncable", "app.group.group_syncable_already_deleted", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("DeleteGroupSyncable", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("DeleteGroupSyncable", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err) } } } @@ -501,7 +501,7 @@ func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableTyp func (a *App) TeamMembersToAdd(since int64, teamID *string, includeRemovedMembers bool) ([]*model.UserTeamIDPair, *model.AppError) { userTeams, err := a.Srv().Store.Group().TeamMembersToAdd(since, teamID, includeRemovedMembers) if err != nil { - return nil, model.NewAppError("TeamMembersToAdd", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("TeamMembersToAdd", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return userTeams, nil @@ -516,7 +516,7 @@ func (a *App) TeamMembersToAdd(since int64, teamID *string, includeRemovedMember func (a *App) ChannelMembersToAdd(since int64, channelID *string, includeRemovedMembers bool) ([]*model.UserChannelIDPair, *model.AppError) { userChannels, err := a.Srv().Store.Group().ChannelMembersToAdd(since, channelID, includeRemovedMembers) if err != nil { - return nil, model.NewAppError("ChannelMembersToAdd", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ChannelMembersToAdd", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return userChannels, nil @@ -525,7 +525,7 @@ func (a *App) ChannelMembersToAdd(since int64, channelID *string, includeRemoved func (a *App) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError) { teamMembers, err := a.Srv().Store.Group().TeamMembersToRemove(teamID) if err != nil { - return nil, model.NewAppError("TeamMembersToRemove", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("TeamMembersToRemove", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teamMembers, nil @@ -534,7 +534,7 @@ func (a *App) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.A func (a *App) ChannelMembersToRemove(teamID *string) ([]*model.ChannelMember, *model.AppError) { channelMembers, err := a.Srv().Store.Group().ChannelMembersToRemove(teamID) if err != nil { - return nil, model.NewAppError("ChannelMembersToRemove", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ChannelMembersToRemove", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channelMembers, nil @@ -543,12 +543,12 @@ func (a *App) ChannelMembersToRemove(teamID *string) ([]*model.ChannelMember, *m func (a *App) GetGroupsByChannel(channelID string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError) { groups, err := a.Srv().Store.Group().GetGroupsByChannel(channelID, opts) if err != nil { - return nil, 0, model.NewAppError("GetGroupsByChannel", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("GetGroupsByChannel", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } count, err := a.Srv().Store.Group().CountGroupsByChannel(channelID, opts) if err != nil { - return nil, 0, model.NewAppError("GetGroupsByChannel", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("GetGroupsByChannel", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return groups, int(count), nil @@ -558,12 +558,12 @@ func (a *App) GetGroupsByChannel(channelID string, opts model.GroupSearchOpts) ( func (a *App) GetGroupsByTeam(teamID string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError) { groups, err := a.Srv().Store.Group().GetGroupsByTeam(teamID, opts) if err != nil { - return nil, 0, model.NewAppError("GetGroupsByTeam", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("GetGroupsByTeam", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } count, err := a.Srv().Store.Group().CountGroupsByTeam(teamID, opts) if err != nil { - return nil, 0, model.NewAppError("GetGroupsByTeam", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("GetGroupsByTeam", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return groups, int(count), nil @@ -572,7 +572,7 @@ func (a *App) GetGroupsByTeam(teamID string, opts model.GroupSearchOpts) ([]*mod func (a *App) GetGroupsAssociatedToChannelsByTeam(teamID string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) { groupsAssociatedByChannelId, err := a.Srv().Store.Group().GetGroupsAssociatedToChannelsByTeam(teamID, opts) if err != nil { - return nil, model.NewAppError("GetGroupsAssociatedToChannelsByTeam", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroupsAssociatedToChannelsByTeam", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return groupsAssociatedByChannelId, nil @@ -581,7 +581,7 @@ func (a *App) GetGroupsAssociatedToChannelsByTeam(teamID string, opts model.Grou func (a *App) GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) { groups, err := a.Srv().Store.Group().GetGroups(page, perPage, opts) if err != nil { - return nil, model.NewAppError("GetGroups", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroups", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return groups, nil @@ -595,7 +595,7 @@ func (a *App) GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model func (a *App) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, int64, *model.AppError) { users, err := a.Srv().Store.Group().TeamMembersMinusGroupMembers(teamID, groupIDs, page, perPage) if err != nil { - return nil, 0, model.NewAppError("TeamMembersMinusGroupMembers", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("TeamMembersMinusGroupMembers", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, u := range users { @@ -641,7 +641,7 @@ func (a *App) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, pag totalCount, err := a.Srv().Store.Group().CountTeamMembersMinusGroupMembers(teamID, groupIDs) if err != nil { - return nil, 0, model.NewAppError("TeamMembersMinusGroupMembers", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("TeamMembersMinusGroupMembers", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, totalCount, nil } @@ -649,7 +649,7 @@ func (a *App) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, pag func (a *App) GetGroupsByIDs(groupIDs []string) ([]*model.Group, *model.AppError) { groups, err := a.Srv().Store.Group().GetByIDs(groupIDs) if err != nil { - return nil, model.NewAppError("GetGroupsByIDs", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetGroupsByIDs", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return groups, nil @@ -663,7 +663,7 @@ func (a *App) GetGroupsByIDs(groupIDs []string) ([]*model.Group, *model.AppError func (a *App) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, int64, *model.AppError) { users, err := a.Srv().Store.Group().ChannelMembersMinusGroupMembers(channelID, groupIDs, page, perPage) if err != nil { - return nil, 0, model.NewAppError("ChannelMembersMinusGroupMembers", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("ChannelMembersMinusGroupMembers", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, u := range users { @@ -709,7 +709,7 @@ func (a *App) ChannelMembersMinusGroupMembers(channelID string, groupIDs []strin totalCount, err := a.Srv().Store.Group().CountChannelMembersMinusGroupMembers(channelID, groupIDs) if err != nil { - return nil, 0, model.NewAppError("ChannelMembersMinusGroupMembers", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("ChannelMembersMinusGroupMembers", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, totalCount, nil } @@ -719,7 +719,7 @@ func (a *App) ChannelMembersMinusGroupMembers(channelID string, groupIDs []strin func (a *App) UserIsInAdminRoleGroup(userID, syncableID string, syncableType model.GroupSyncableType) (bool, *model.AppError) { groupIDs, err := a.Srv().Store.Group().AdminRoleGroupsForSyncableMember(userID, syncableID, syncableType) if err != nil { - return false, model.NewAppError("UserIsInAdminRoleGroup", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return false, model.NewAppError("UserIsInAdminRoleGroup", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(groupIDs) == 0 { @@ -738,9 +738,9 @@ func (a *App) UpsertGroupMembers(groupID string, userIDs []string) ([]*model.Gro case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("UpsertGroupMembers", "app.group.uniqueness_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpsertGroupMembers", "app.group.uniqueness_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("UpsertGroupMembers", "app.update_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpsertGroupMembers", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -762,7 +762,7 @@ func (a *App) DeleteGroupMembers(groupID string, userIDs []string) ([]*model.Gro case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("DeleteGroupMember", "app.group.uniqueness_error", nil, "", http.StatusBadRequest).Wrap(invErr) + return nil, model.NewAppError("DeleteGroupMember", "app.group.uniqueness_error", nil, "", http.StatusBadRequest).Wrap(err) default: return nil, model.NewAppError("DeleteGroupMember", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err) } diff --git a/app/import.go b/app/import.go index 578a21ac6b..5f7b51441a 100644 --- a/app/import.go +++ b/app/import.go @@ -196,7 +196,7 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader var line LineImportData if err := decoder.Decode(&line); err != nil { - return model.NewAppError("BulkImport", "app.import.bulk_import.json_decode.error", nil, err.Error(), http.StatusBadRequest), lineNumber + return model.NewAppError("BulkImport", "app.import.bulk_import.json_decode.error", nil, "", http.StatusBadRequest).Wrap(err), lineNumber } if err := processAttachments(&line, importPath, attachedFiles); err != nil { @@ -267,7 +267,7 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader } if err := scanner.Err(); err != nil { - return model.NewAppError("BulkImport", "app.import.bulk_import.file_scan.error", nil, err.Error(), http.StatusInternalServerError), 0 + return model.NewAppError("BulkImport", "app.import.bulk_import.file_scan.error", nil, "", http.StatusInternalServerError).Wrap(err), 0 } return nil, 0 diff --git a/app/import_functions.go b/app/import_functions.go index f0782f9610..b2637b4aeb 100644 --- a/app/import_functions.go +++ b/app/import_functions.go @@ -214,11 +214,11 @@ func (a *App) importTeam(c request.CTX, data *TeamImportData, dryRun bool) *mode var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return model.NewAppError("BulkImport", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("BulkImport", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(err) case errors.As(err, &invErr): - return model.NewAppError("BulkImport", "app.team.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("BulkImport", "app.team.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return model.NewAppError("BulkImport", "app.team.update.updating.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("BulkImport", "app.team.update.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } } @@ -238,7 +238,7 @@ func (a *App) importChannel(c request.CTX, data *ChannelImportData, dryRun bool) team, err := a.Srv().Store.Team().GetByName(*data.Team) if err != nil { - return model.NewAppError("BulkImport", "app.import.import_channel.team_not_found.error", map[string]any{"TeamName": *data.Team}, err.Error(), http.StatusBadRequest) + return model.NewAppError("BulkImport", "app.import.import_channel.team_not_found.error", map[string]any{"TeamName": *data.Team}, "", http.StatusBadRequest).Wrap(err) } var channel *model.Channel @@ -353,7 +353,7 @@ func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *mode // If no AuthData or Password is specified, we must generate a password. password, err = generatePassword(*a.Config().PasswordSettings.MinimumLength) if err != nil { - return model.NewAppError("importUser", "app.import.generate_password.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("importUser", "app.import.generate_password.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } authData = nil } @@ -501,20 +501,20 @@ func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *mode case errors.As(err, &appErr): return appErr case errors.Is(err, users.AcceptedDomainError): - return model.NewAppError("importUser", "api.user.create_user.accepted_domain.app_error", nil, "", http.StatusBadRequest) + return model.NewAppError("importUser", "api.user.create_user.accepted_domain.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.Is(err, users.UserStoreIsEmptyError): - return model.NewAppError("importUser", "app.user.store_is_empty.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importUser", "app.user.store_is_empty.app_error", nil, "", http.StatusInternalServerError).Wrap(err) case errors.As(err, &invErr): switch invErr.Field { case "email": - return model.NewAppError("importUser", "app.user.save.email_exists.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("importUser", "app.user.save.email_exists.app_error", nil, "", http.StatusBadRequest).Wrap(err) case "username": - return model.NewAppError("importUser", "app.user.save.username_exists.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("importUser", "app.user.save.username_exists.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return model.NewAppError("importUser", "app.user.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("importUser", "app.user.save.existing.app_error", nil, "", http.StatusBadRequest).Wrap(err) } default: - return model.NewAppError("importUser", "app.user.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importUser", "app.user.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -553,9 +553,9 @@ func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *mode var invErr *store.ErrInvalidInput switch { case errors.As(nErr, &invErr): - return model.NewAppError("importUser", "app.user.update_auth_data.email_exists.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("importUser", "app.user.update_auth_data.email_exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) default: - return model.NewAppError("importUser", "app.user.update_auth_data.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importUser", "app.user.update_auth_data.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } } @@ -723,7 +723,7 @@ func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *mode if len(preferences) > 0 { if err := a.Srv().Store.Preference().Save(preferences); err != nil { - return model.NewAppError("BulkImport", "app.import.import_user.save_preferences.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("BulkImport", "app.import.import_user.save_preferences.error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -756,7 +756,7 @@ func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]UserTeamI isAdminByTeamId := map[string]bool{} existingMemberships, nErr := a.Srv().Store.Team().GetTeamsForUser(context.Background(), user.Id, "", true) if nErr != nil { - return model.NewAppError("importUserTeams", "app.team.get_members.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importUserTeams", "app.team.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } existingMembershipsByTeamId := map[string]*model.TeamMember{} for _, teamMembership := range existingMemberships { @@ -839,7 +839,7 @@ func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]UserTeamI case errors.As(nErr, &appErr): return appErr default: - return model.NewAppError("importUserTeams", "app.team.save_member.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importUserTeams", "app.team.save_member.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -855,11 +855,11 @@ func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]UserTeamI case errors.As(nErr, &appErr): // in case we haven't converted to plain error. return appErr case errors.As(nErr, &conflictErr): - return model.NewAppError("BulkImport", "app.import.import_user_teams.save_members.conflict.app_error", nil, nErr.Error(), http.StatusBadRequest) + return model.NewAppError("BulkImport", "app.import.import_user_teams.save_members.conflict.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &limitExceededErr): - return model.NewAppError("BulkImport", "app.import.import_user_teams.save_members.max_accounts.app_error", nil, nErr.Error(), http.StatusBadRequest) + return model.NewAppError("BulkImport", "app.import.import_user_teams.save_members.max_accounts.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) default: // last fallback in case it doesn't map to an existing app error. - return model.NewAppError("BulkImport", "app.import.import_user_teams.save_members.error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("BulkImport", "app.import.import_user_teams.save_members.error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } } @@ -878,7 +878,7 @@ func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]UserTeamI if len(teamThemePreferencesByID[team.Id]) > 0 { pref := teamThemePreferencesByID[team.Id] if err := a.Srv().Store.Preference().Save(pref); err != nil { - return model.NewAppError("BulkImport", "app.import.import_user_teams.save_preferences.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("BulkImport", "app.import.import_user_teams.save_preferences.error", nil, "", http.StatusInternalServerError).Wrap(err) } } channelsToImport := channels[team.Id] @@ -915,7 +915,7 @@ func (a *App) importUserChannels(c request.CTX, user *model.User, team *model.Te isAdminByChannelId := map[string]bool{} existingMemberships, nErr := a.Srv().Store.Channel().GetMembersForUser(team.Id, user.Id) if nErr != nil { - return model.NewAppError("importUserChannels", "app.channel.get_members.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importUserChannels", "app.channel.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } existingMembershipsByChannelId := map[string]model.ChannelMember{} for _, channelMembership := range existingMemberships { @@ -1012,9 +1012,9 @@ func (a *App) importUserChannels(c request.CTX, user *model.User, team *model.Te case errors.As(nErr, &appErr): return appErr case errors.As(nErr, &nfErr): - return model.NewAppError("importUserChannels", MissingChannelMemberError, nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("importUserChannels", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return model.NewAppError("importUserChannels", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importUserChannels", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -1028,12 +1028,12 @@ func (a *App) importUserChannels(c request.CTX, user *model.User, team *model.Te case errors.As(nErr, &cErr): switch cErr.Resource { case "ChannelMembers": - return model.NewAppError("importUserChannels", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest) + return model.NewAppError("importUserChannels", "app.channel.save_member.exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) } case errors.As(nErr, &appErr): return appErr default: - return model.NewAppError("importUserChannels", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importUserChannels", "app.channel.create_direct_channel.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } } @@ -1052,7 +1052,7 @@ func (a *App) importUserChannels(c request.CTX, user *model.User, team *model.Te if len(channelPreferencesByID[channel.Id]) > 0 { pref := channelPreferencesByID[channel.Id] if err := a.Srv().Store.Preference().Save(pref); err != nil { - return model.NewAppError("BulkImport", "app.import.import_user_channels.save_preferences.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("BulkImport", "app.import.import_user_channels.save_preferences.error", nil, "", http.StatusInternalServerError).Wrap(err) } } } @@ -1068,7 +1068,7 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post) *model. var user *model.User var nErr error if user, nErr = a.Srv().Store.User().GetByUsername(*data.User); nErr != nil { - return model.NewAppError("BulkImport", "app.import.import_post.user_not_found.error", map[string]any{"Username": data.User}, nErr.Error(), http.StatusBadRequest) + return model.NewAppError("BulkImport", "app.import.import_post.user_not_found.error", map[string]any{"Username": data.User}, "", http.StatusBadRequest).Wrap(nErr) } reaction := &model.Reaction{ @@ -1083,7 +1083,7 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post) *model. case errors.As(nErr, &appErr): return appErr default: - return model.NewAppError("importReaction", "app.reaction.save.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importReaction", "app.reaction.save.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -1117,7 +1117,7 @@ func (a *App) importReplies(c request.CTX, data []ReplyImportData, post *model.P // Check if this post already exists. replies, nErr := a.Srv().Store.Post().GetPostsCreatedAt(post.ChannelId, *replyData.CreateAt) if nErr != nil { - return model.NewAppError("importReplies", "app.post.get_posts_created_at.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importReplies", "app.post.get_posts_created_at.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } var reply *model.Post @@ -1174,15 +1174,15 @@ func (a *App) importReplies(c request.CTX, data []ReplyImportData, post *model.P case errors.As(err, &appErr): return appErr case errors.As(err, &invErr): - return model.NewAppError("importReplies", "app.post.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("importReplies", "app.post.save.existing.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return model.NewAppError("importReplies", "app.post.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("importReplies", "app.post.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } } if _, _, nErr := a.Srv().Store.Post().OverwriteMultiple(postsForOverwriteList); nErr != nil { - return model.NewAppError("importReplies", "app.post.overwrite.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("importReplies", "app.post.overwrite.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } for _, postWithData := range postsWithData { @@ -1200,7 +1200,7 @@ func (a *App) importAttachment(c request.CTX, data *AttachmentImportData, post * if data.Data != nil { zipFile, err := data.Data.Open() if err != nil { - return nil, model.NewAppError("BulkImport", "app.import.attachment.bad_file.error", map[string]any{"FilePath": *data.Path}, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("BulkImport", "app.import.attachment.bad_file.error", map[string]any{"FilePath": *data.Path}, "", http.StatusBadRequest).Wrap(err) } defer zipFile.Close() name = data.Data.Name @@ -1208,7 +1208,7 @@ func (a *App) importAttachment(c request.CTX, data *AttachmentImportData, post * } else { realFile, err := os.Open(*data.Path) if err != nil { - return nil, model.NewAppError("BulkImport", "app.import.attachment.bad_file.error", map[string]any{"FilePath": *data.Path}, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("BulkImport", "app.import.attachment.bad_file.error", map[string]any{"FilePath": *data.Path}, "", http.StatusBadRequest).Wrap(err) } defer realFile.Close() name = realFile.Name() @@ -1275,7 +1275,7 @@ func (a *App) getUsersByUsernames(usernames []string) (map[string]*model.User, * uniqueUsernames := utils.RemoveDuplicatesFromStringArray(usernames) allUsers, err := a.Srv().Store.User().GetProfilesByUsernames(uniqueUsernames, nil) if err != nil { - return nil, model.NewAppError("BulkImport", "app.import.get_users_by_username.some_users_not_found.error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("BulkImport", "app.import.get_users_by_username.some_users_not_found.error", nil, "", http.StatusBadRequest).Wrap(err) } if len(allUsers) != len(uniqueUsernames) { @@ -1292,7 +1292,7 @@ func (a *App) getUsersByUsernames(usernames []string) (map[string]*model.User, * func (a *App) getTeamsByNames(names []string) (map[string]*model.Team, *model.AppError) { allTeams, err := a.Srv().Store.Team().GetByNames(names) if err != nil { - return nil, model.NewAppError("BulkImport", "app.import.get_teams_by_names.some_teams_not_found.error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("BulkImport", "app.import.get_teams_by_names.some_teams_not_found.error", nil, "", http.StatusBadRequest).Wrap(err) } teams := make(map[string]*model.Team) @@ -1305,7 +1305,7 @@ func (a *App) getTeamsByNames(names []string) (map[string]*model.Team, *model.Ap func (a *App) getChannelsByNames(names []string, teamID string) (map[string]*model.Channel, *model.AppError) { allChannels, err := a.Srv().Store.Channel().GetByNames(teamID, names, true) if err != nil { - return nil, model.NewAppError("BulkImport", "app.import.get_teams_by_names.some_teams_not_found.error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("BulkImport", "app.import.get_teams_by_names.some_teams_not_found.error", nil, "", http.StatusBadRequest).Wrap(err) } channels := make(map[string]*model.Channel) @@ -1327,7 +1327,7 @@ func (a *App) getChannelsForPosts(teams map[string]*model.Team, data []*PostImpo var err error channel, err = a.Srv().Store.Channel().GetByName(teams[teamName].Id, *postData.Channel, true) if err != nil { - return nil, model.NewAppError("BulkImport", "app.import.import_post.channel_not_found.error", map[string]any{"ChannelName": *postData.Channel}, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("BulkImport", "app.import.import_post.channel_not_found.error", map[string]any{"ChannelName": *postData.Channel}, "", http.StatusBadRequest).Wrap(err) } teamChannels[teamName][*postData.Channel] = channel } @@ -1399,7 +1399,7 @@ func (a *App) importMultiplePostLines(c request.CTX, lines []LineImportWorkerDat // Check if this post already exists. posts, nErr := a.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *line.Post.CreateAt) if nErr != nil { - return line.LineNumber, model.NewAppError("importMultiplePostLines", "app.post.get_posts_created_at.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return line.LineNumber, model.NewAppError("importMultiplePostLines", "app.post.get_posts_created_at.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } var post *model.Post @@ -1463,9 +1463,9 @@ func (a *App) importMultiplePostLines(c request.CTX, lines []LineImportWorkerDat case errors.As(nErr, &appErr): retErr = appErr case errors.As(nErr, &invErr): - retErr = model.NewAppError("importMultiplePostLines", "app.post.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + retErr = model.NewAppError("importMultiplePostLines", "app.post.save.existing.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) default: - retErr = model.NewAppError("importMultiplePostLines", "app.post.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + retErr = model.NewAppError("importMultiplePostLines", "app.post.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } if idx != -1 && idx < len(postsForCreateList) { @@ -1482,10 +1482,10 @@ func (a *App) importMultiplePostLines(c request.CTX, lines []LineImportWorkerDat if idx != -1 && idx < len(postsForOverwriteList) { post := postsForOverwriteList[idx] if lineNumber, ok := postsForOverwriteMap[getPostStrID(post)]; ok { - return lineNumber, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, err.Error(), http.StatusInternalServerError) + return lineNumber, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } - return 0, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, postWithData := range postsWithData { @@ -1506,7 +1506,7 @@ func (a *App) importMultiplePostLines(c request.CTX, lines []LineImportWorkerDat if len(preferences) > 0 { if err := a.Srv().Store.Preference().Save(preferences); err != nil { - return postWithData.lineNumber, model.NewAppError("BulkImport", "app.import.import_post.save_preferences.error", nil, err.Error(), http.StatusInternalServerError) + return postWithData.lineNumber, model.NewAppError("BulkImport", "app.import.import_post.save_preferences.error", nil, "", http.StatusInternalServerError).Wrap(err) } } } @@ -1589,13 +1589,13 @@ func (a *App) importDirectChannel(c request.CTX, data *DirectChannelImportData, if len(userIDs) == 2 { ch, err := a.createDirectChannel(c, userIDs[0], userIDs[1]) if err != nil && err.Id != store.ChannelExistsError { - return model.NewAppError("BulkImport", "app.import.import_direct_channel.create_direct_channel.error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("BulkImport", "app.import.import_direct_channel.create_direct_channel.error", nil, "", http.StatusBadRequest).Wrap(err) } channel = ch } else { ch, err := a.createGroupChannel(c, userIDs) if err != nil && err.Id != store.ChannelExistsError { - return model.NewAppError("BulkImport", "app.import.import_direct_channel.create_group_channel.error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("BulkImport", "app.import.import_direct_channel.create_group_channel.error", nil, "", http.StatusBadRequest).Wrap(err) } channel = ch } @@ -1629,14 +1629,14 @@ func (a *App) importDirectChannel(c request.CTX, data *DirectChannelImportData, appErr.StatusCode = http.StatusBadRequest return appErr default: - return model.NewAppError("importDirectChannel", "app.preference.save.updating.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("importDirectChannel", "app.preference.save.updating.app_error", nil, "", http.StatusBadRequest).Wrap(err) } } if data.Header != nil { channel.Header = *data.Header if _, appErr := a.Srv().Store.Channel().Update(channel); appErr != nil { - return model.NewAppError("BulkImport", "app.import.import_direct_channel.update_header_failed.error", nil, appErr.Error(), http.StatusBadRequest) + return model.NewAppError("BulkImport", "app.import.import_direct_channel.update_header_failed.error", nil, "", http.StatusBadRequest).Wrap(appErr) } } @@ -1694,13 +1694,13 @@ func (a *App) importMultipleDirectPostLines(c request.CTX, lines []LineImportWor if len(userIDs) == 2 { ch, err = a.GetOrCreateDirectChannel(c, userIDs[0], userIDs[1]) if err != nil && err.Id != store.ChannelExistsError { - return line.LineNumber, model.NewAppError("BulkImport", "app.import.import_direct_post.create_direct_channel.error", nil, err.Error(), http.StatusBadRequest) + return line.LineNumber, model.NewAppError("BulkImport", "app.import.import_direct_post.create_direct_channel.error", nil, "", http.StatusBadRequest).Wrap(err) } channel = ch } else { ch, err = a.createGroupChannel(c, userIDs) if err != nil && err.Id != store.ChannelExistsError { - return line.LineNumber, model.NewAppError("BulkImport", "app.import.import_direct_post.create_group_channel.error", nil, err.Error(), http.StatusBadRequest) + return line.LineNumber, model.NewAppError("BulkImport", "app.import.import_direct_post.create_group_channel.error", nil, "", http.StatusBadRequest).Wrap(err) } channel = ch } @@ -1710,7 +1710,7 @@ func (a *App) importMultipleDirectPostLines(c request.CTX, lines []LineImportWor // Check if this post already exists. posts, nErr := a.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *line.DirectPost.CreateAt) if nErr != nil { - return line.LineNumber, model.NewAppError("BulkImport", "app.post.get_posts_created_at.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return line.LineNumber, model.NewAppError("BulkImport", "app.post.get_posts_created_at.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } var post *model.Post @@ -1774,9 +1774,9 @@ func (a *App) importMultipleDirectPostLines(c request.CTX, lines []LineImportWor case errors.As(err, &appErr): retErr = appErr case errors.As(err, &invErr): - retErr = model.NewAppError("importMultiplePostLines", "app.post.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + retErr = model.NewAppError("importMultiplePostLines", "app.post.save.existing.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - retErr = model.NewAppError("importMultiplePostLines", "app.post.save.app_error", nil, err.Error(), http.StatusInternalServerError) + retErr = model.NewAppError("importMultiplePostLines", "app.post.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if idx != -1 && idx < len(postsForCreateList) { @@ -1792,10 +1792,10 @@ func (a *App) importMultipleDirectPostLines(c request.CTX, lines []LineImportWor if idx != -1 && idx < len(postsForOverwriteList) { post := postsForOverwriteList[idx] if lineNumber, ok := postsForOverwriteMap[getPostStrID(post)]; ok { - return lineNumber, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, err.Error(), http.StatusInternalServerError) + return lineNumber, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } - return 0, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, postWithData := range postsWithData { @@ -1815,7 +1815,7 @@ func (a *App) importMultipleDirectPostLines(c request.CTX, lines []LineImportWor if len(preferences) > 0 { if err := a.Srv().Store.Preference().Save(preferences); err != nil { - return postWithData.lineNumber, model.NewAppError("BulkImport", "app.import.import_post.save_preferences.error", nil, err.Error(), http.StatusInternalServerError) + return postWithData.lineNumber, model.NewAppError("BulkImport", "app.import.import_post.save_preferences.error", nil, "", http.StatusInternalServerError).Wrap(err) } } } @@ -1861,7 +1861,7 @@ func (a *App) importEmoji(data *EmojiImportData, dryRun bool) *model.AppError { if err != nil { var nfErr *store.ErrNotFound if !errors.As(err, &nfErr) { - return model.NewAppError("importEmoji", "app.emoji.get_by_name.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("importEmoji", "app.emoji.get_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1892,7 +1892,7 @@ func (a *App) importEmoji(data *EmojiImportData, dryRun bool) *model.AppError { if !alreadyExists { if _, err := a.Srv().Store.Emoji().Save(emoji); err != nil { - return model.NewAppError("importEmoji", "api.emoji.create.internal_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("importEmoji", "api.emoji.create.internal_error", nil, "", http.StatusBadRequest).Wrap(err) } } diff --git a/app/import_functions_test.go b/app/import_functions_test.go index 8ac8ff6e69..f397f635e3 100644 --- a/app/import_functions_test.go +++ b/app/import_functions_test.go @@ -4150,45 +4150,45 @@ func TestImportImportEmoji(t *testing.T) { testImage := filepath.Join(testsDir, "test.png") data := EmojiImportData{Name: ptrStr(model.NewId())} - err := th.App.importEmoji(&data, true) - assert.NotNil(t, err, "Invalid emoji should have failed dry run") + appErr := th.App.importEmoji(&data, true) + assert.NotNil(t, appErr, "Invalid emoji should have failed dry run") emoji, nErr := th.App.Srv().Store.Emoji().GetByName(context.Background(), *data.Name, true) assert.Nil(t, emoji, "Emoji should not have been imported") assert.Error(t, nErr) data.Image = ptrStr(testImage) - err = th.App.importEmoji(&data, true) - assert.Nil(t, err, "Valid emoji should have passed dry run") + appErr = th.App.importEmoji(&data, true) + assert.Nil(t, appErr, "Valid emoji should have passed dry run") data = EmojiImportData{Name: ptrStr(model.NewId())} - err = th.App.importEmoji(&data, false) - assert.NotNil(t, err, "Invalid emoji should have failed apply mode") + appErr = th.App.importEmoji(&data, false) + assert.NotNil(t, appErr, "Invalid emoji should have failed apply mode") data.Image = ptrStr("non-existent-file") - err = th.App.importEmoji(&data, false) - assert.NotNil(t, err, "Emoji with bad image file should have failed apply mode") + appErr = th.App.importEmoji(&data, false) + assert.NotNil(t, appErr, "Emoji with bad image file should have failed apply mode") data.Image = ptrStr(testImage) - err = th.App.importEmoji(&data, false) - assert.Nil(t, err, "Valid emoji should have succeeded apply mode") + appErr = th.App.importEmoji(&data, false) + assert.Nil(t, appErr, "Valid emoji should have succeeded apply mode") emoji, nErr = th.App.Srv().Store.Emoji().GetByName(context.Background(), *data.Name, true) assert.NotNil(t, emoji, "Emoji should have been imported") assert.NoError(t, nErr, "Emoji should have been imported without any error") - err = th.App.importEmoji(&data, false) - assert.Nil(t, err, "Second run should have succeeded apply mode") + appErr = th.App.importEmoji(&data, false) + assert.Nil(t, appErr, "Second run should have succeeded apply mode") data = EmojiImportData{Name: ptrStr("smiley"), Image: ptrStr(testImage)} - err = th.App.importEmoji(&data, false) - assert.Nil(t, err, "System emoji should not fail") + appErr = th.App.importEmoji(&data, false) + assert.Nil(t, appErr, "System emoji should not fail") largeImage := filepath.Join(testsDir, "large_image_file.jpg") data = EmojiImportData{Name: ptrStr(model.NewId()), Image: ptrStr(largeImage)} - err = th.App.importEmoji(&data, false) - require.NotNil(t, err) - require.Contains(t, err.DetailedError, utils.SizeLimitExceeded.Error()) + appErr = th.App.importEmoji(&data, false) + require.NotNil(t, appErr) + require.ErrorIs(t, appErr.Unwrap(), utils.SizeLimitExceeded) } func TestImportAttachment(t *testing.T) { diff --git a/app/integration_action.go b/app/integration_action.go index 35b93a956f..18e41fde75 100644 --- a/app/integration_action.go +++ b/app/integration_action.go @@ -98,7 +98,7 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return "", model.NewAppError("DoPostActionWithCookie", "app.post.get.app_error", nil, "", http.StatusNotFound).Wrap(nfErr) + return "", model.NewAppError("DoPostActionWithCookie", "app.post.get.app_error", nil, "", http.StatusNotFound).Wrap(result.NErr) default: return "", model.NewAppError("DoPostActionWithCookie", "app.post.get.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } @@ -116,7 +116,7 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(nfErr) + return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get.find.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } @@ -195,7 +195,7 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI var nfErr *store.ErrNotFound switch { case errors.As(ur.NErr, &nfErr): - return "", model.NewAppError("DoPostActionWithCookie", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nfErr) + return "", model.NewAppError("DoPostActionWithCookie", MissingAccountError, nil, "", http.StatusNotFound).Wrap(ur.NErr) default: return "", model.NewAppError("DoPostActionWithCookie", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(ur.NErr) } @@ -209,7 +209,7 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI var nfErr *store.ErrNotFound switch { case errors.As(tr.NErr, &nfErr): - return "", model.NewAppError("DoPostActionWithCookie", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(nfErr) + return "", model.NewAppError("DoPostActionWithCookie", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(tr.NErr) default: return "", model.NewAppError("DoPostActionWithCookie", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(tr.NErr) } @@ -313,7 +313,7 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI func (a *App) DoActionRequest(c *request.Context, rawURL string, body []byte) (*http.Response, *model.AppError) { inURL, err := url.Parse(rawURL) if err != nil { - return nil, model.NewAppError("DoActionRequest", "api.post.do_action.action_integration.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("DoActionRequest", "api.post.do_action.action_integration.app_error", nil, "", http.StatusBadRequest).Wrap(err) } rawURLPath := path.Clean(rawURL) @@ -323,7 +323,7 @@ func (a *App) DoActionRequest(c *request.Context, rawURL string, body []byte) (* req, err := http.NewRequest("POST", rawURL, bytes.NewReader(body)) if err != nil { - return nil, model.NewAppError("DoActionRequest", "api.post.do_action.action_integration.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("DoActionRequest", "api.post.do_action.action_integration.app_error", nil, "", http.StatusBadRequest).Wrap(err) } req.Header.Set("Content-Type", "application/json") req.Header.Set("Accept", "application/json") @@ -447,7 +447,7 @@ func (ch *Channels) doPluginRequest(c *request.Context, method, rawURL string, v func (a *App) doLocalWarnMetricsRequest(c *request.Context, rawURL string, upstreamRequest *model.PostActionIntegrationRequest) *model.AppError { _, err := url.Parse(rawURL) if err != nil { - return model.NewAppError("doLocalWarnMetricsRequest", "api.post.do_action.action_integration.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("doLocalWarnMetricsRequest", "api.post.do_action.action_integration.app_error", nil, "", http.StatusBadRequest).Wrap(err) } warnMetricId := filepath.Base(rawURL) diff --git a/app/integrations.go b/app/integrations.go index 9042f1e1bb..812c7cfaa8 100644 --- a/app/integrations.go +++ b/app/integrations.go @@ -38,7 +38,7 @@ func (ch *Channels) getInstalledIntegrations() ([]*model.InstalledIntegration, * plugins, err := pluginsEnvironment.Available() if err != nil { - return nil, model.NewAppError("getInstalledIntegrations", "app.plugin.sync.read_local_folder.app_error", nil, err.Error(), 0) + return nil, model.NewAppError("getInstalledIntegrations", "app.plugin.sync.read_local_folder.app_error", nil, "", 0).Wrap(err) } pluginStates := ch.cfgSvc.Config().PluginSettings.PluginStates diff --git a/app/job.go b/app/job.go index 5ba697f3e1..0eaeb82d7a 100644 --- a/app/job.go +++ b/app/job.go @@ -17,9 +17,9 @@ func (a *App) GetJob(id string) (*model.Job, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetJob", "app.job.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetJob", "app.job.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetJob", "app.job.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetJob", "app.job.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -33,7 +33,7 @@ func (a *App) GetJobsPage(page int, perPage int) ([]*model.Job, *model.AppError) func (a *App) GetJobs(offset int, limit int) ([]*model.Job, *model.AppError) { jobs, err := a.Srv().Store.Job().GetAllPage(offset, limit) if err != nil { - return nil, model.NewAppError("GetJobs", "app.job.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetJobs", "app.job.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return jobs, nil @@ -46,7 +46,7 @@ func (a *App) GetJobsByTypePage(jobType string, page int, perPage int) ([]*model func (a *App) GetJobsByType(jobType string, offset int, limit int) ([]*model.Job, *model.AppError) { jobs, err := a.Srv().Store.Job().GetAllByTypePage(jobType, offset, limit) if err != nil { - return nil, model.NewAppError("GetJobsByType", "app.job.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetJobsByType", "app.job.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return jobs, nil @@ -59,7 +59,7 @@ func (a *App) GetJobsByTypesPage(jobType []string, page int, perPage int) ([]*mo func (a *App) GetJobsByTypes(jobTypes []string, offset int, limit int) ([]*model.Job, *model.AppError) { jobs, err := a.Srv().Store.Job().GetAllByTypesPage(jobTypes, offset, limit) if err != nil { - return nil, model.NewAppError("GetJobsByType", "app.job.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetJobsByType", "app.job.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return jobs, nil } diff --git a/app/ldap.go b/app/ldap.go index a782b4715c..60b09928cb 100644 --- a/app/ldap.go +++ b/app/ldap.go @@ -171,7 +171,7 @@ func (a *App) MigrateIdLDAP(toAttribute string) *model.AppError { case *model.AppError: return err default: - return model.NewAppError("IdMigrateLDAP", "ent.ldap_id_migrate.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("IdMigrateLDAP", "ent.ldap_id_migrate.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return nil @@ -182,18 +182,18 @@ func (a *App) MigrateIdLDAP(toAttribute string) *model.AppError { func (a *App) writeLdapFile(filename string, fileData *multipart.FileHeader) *model.AppError { file, err := fileData.Open() if err != nil { - return model.NewAppError("AddLdapCertificate", "api.admin.add_certificate.open.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("AddLdapCertificate", "api.admin.add_certificate.open.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } defer file.Close() data, err := io.ReadAll(file) if err != nil { - return model.NewAppError("AddLdapCertificate", "api.admin.add_certificate.saving.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("AddLdapCertificate", "api.admin.add_certificate.saving.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } err = a.Srv().platform.SetConfigFile(filename, data) if err != nil { - return model.NewAppError("AddLdapCertificate", "api.admin.add_certificate.saving.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("AddLdapCertificate", "api.admin.add_certificate.saving.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -235,7 +235,7 @@ func (a *App) AddLdapPrivateCertificate(fileData *multipart.FileHeader) *model.A func (a *App) removeLdapFile(filename string) *model.AppError { if err := a.Srv().platform.RemoveConfigFile(filename); err != nil { - return model.NewAppError("RemoveLdapFile", "api.admin.remove_certificate.delete.app_error", map[string]any{"Filename": filename}, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RemoveLdapFile", "api.admin.remove_certificate.delete.app_error", map[string]any{"Filename": filename}, "", http.StatusInternalServerError).Wrap(err) } return nil } diff --git a/app/license.go b/app/license.go index bf359752cf..81cc6cd16e 100644 --- a/app/license.go +++ b/app/license.go @@ -65,9 +65,9 @@ func (w *licenseWrapper) RequestTrialLicense(requesterID string, users int, term var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return model.NewAppError("RequestTrialLicense", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("RequestTrialLicense", MissingAccountError, nil, "", http.StatusNotFound).Wrap(err) default: - return model.NewAppError("RequestTrialLicense", "app.user.get_by_username.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RequestTrialLicense", "app.user.get_by_username.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -166,12 +166,12 @@ func (s *Server) SaveLicense(licenseBytes []byte) (*model.License, *model.AppErr var license model.License if jsonErr := json.Unmarshal([]byte(licenseStr), &license); jsonErr != nil { - return nil, model.NewAppError("addLicense", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("addLicense", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr) } uniqueUserCount, err := s.Store.User().Count(model.UserCountOptions{}) if err != nil { - return nil, model.NewAppError("addLicense", "api.license.add_license.invalid_count.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("addLicense", "api.license.add_license.invalid_count.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if uniqueUserCount > int64(*license.Features.Users) { @@ -226,7 +226,7 @@ func (s *Server) SaveLicense(licenseBytes []byte) (*model.License, *model.AppErr case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("addLicense", "api.license.add_license.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("addLicense", "api.license.add_license.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -316,7 +316,7 @@ func (s *Server) RemoveLicense() *model.AppError { sysVar.Value = "" if err := s.Store.System().SaveOrUpdate(sysVar); err != nil { - return model.NewAppError("RemoveLicense", "app.system.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RemoveLicense", "app.system.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } s.SetLicense(nil) @@ -397,7 +397,7 @@ func (s *Server) GenerateRenewalToken(expiration time.Duration) (string, *model. activeUsers, err := s.Store.User().Count(model.UserCountOptions{}) if err != nil { return "", model.NewAppError("GenerateRenewalToken", "app.license.generate_renewal_token.app_error", - nil, err.Error(), http.StatusInternalServerError) + nil, "", http.StatusInternalServerError).Wrap(err) } expirationTime := time.Now().UTC().Add(expiration) @@ -412,7 +412,7 @@ func (s *Server) GenerateRenewalToken(expiration time.Duration) (string, *model. token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) tokenString, err := token.SignedString([]byte(license.Customer.Email)) if err != nil { - return "", model.NewAppError("GenerateRenewalToken", "app.license.generate_renewal_token.app_error", nil, err.Error(), http.StatusInternalServerError) + return "", model.NewAppError("GenerateRenewalToken", "app.license.generate_renewal_token.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return tokenString, nil diff --git a/app/login.go b/app/login.go index 375d50d914..620c843f9c 100644 --- a/app/login.go +++ b/app/login.go @@ -74,7 +74,7 @@ func (a *App) AuthenticateUserForLogin(c *request.Context, id, loginId, password if nfErr := new(store.ErrNotFound); err != nil && !errors.As(err, &nfErr) { mlog.Debug("Error retrieving the cws token from the store", mlog.Err(err)) return nil, model.NewAppError("AuthenticateUserForLogin", - "api.user.login_by_cws.invalid_token.app_error", nil, "", http.StatusInternalServerError) + "api.user.login_by_cws.invalid_token.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // If token is stored in the database that means it was used if token != nil { diff --git a/app/notification.go b/app/notification.go index fac001cc6d..b1ea390836 100644 --- a/app/notification.go +++ b/app/notification.go @@ -257,7 +257,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea var nfErr *store.ErrNotFound if err != nil && !errors.As(err, &nfErr) { - mac <- model.NewAppError("SendNotifications", "app.channel.autofollow.app_error", nil, err.Error(), http.StatusInternalServerError) + mac <- model.NewAppError("SendNotifications", "app.channel.autofollow.app_error", nil, "", http.StatusInternalServerError).Wrap(err) return } @@ -280,7 +280,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea } threadMembership, err := a.Srv().Store.Thread().MaintainMembership(userID, post.RootId, opts) if err != nil { - mac <- model.NewAppError("SendNotifications", "app.channel.autofollow.app_error", nil, err.Error(), http.StatusInternalServerError) + mac <- model.NewAppError("SendNotifications", "app.channel.autofollow.app_error", nil, "", http.StatusInternalServerError).Wrap(err) return } @@ -1128,7 +1128,7 @@ func (a *App) insertGroupMentions(group *model.Group, channel *model.Channel, pr } if err != nil { - return false, model.NewAppError("insertGroupMentions", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return false, model.NewAppError("insertGroupMentions", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } if mentions.Mentions == nil { diff --git a/app/notification_push.go b/app/notification_push.go index 1065dbf1fe..757764c613 100644 --- a/app/notification_push.go +++ b/app/notification_push.go @@ -232,14 +232,14 @@ func (a *App) clearPushNotificationSync(c request.CTX, currentSessionId, userID, unreadCount, err := a.Srv().Store.User().GetUnreadCount(userID) if err != nil { - return model.NewAppError("clearPushNotificationSync", "app.user.get_unread_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("clearPushNotificationSync", "app.user.get_unread_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } msg.Badge = int(unreadCount) if msg.IsCRTEnabled { totalUnreadMentions, err := a.Srv().Store.Thread().GetTotalUnreadMentions(userID, "", model.GetUserThreadsOpts{}) if err != nil { - return model.NewAppError("clearPushNotificationSync", "app.user.get_thread_count_for_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("clearPushNotificationSync", "app.user.get_thread_count_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } msg.Badge += int(totalUnreadMentions) } @@ -270,7 +270,7 @@ func (a *App) updateMobileAppBadgeSync(userID string) *model.AppError { unreadCount, err := a.Srv().Store.User().GetUnreadCount(userID) if err != nil { - return model.NewAppError("updateMobileAppBadgeSync", "app.user.get_unread_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("updateMobileAppBadgeSync", "app.user.get_unread_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } msg.Badge = int(unreadCount) diff --git a/app/oauth.go b/app/oauth.go index e205641522..d9b41e4210 100644 --- a/app/oauth.go +++ b/app/oauth.go @@ -48,9 +48,9 @@ func (a *App) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppEr case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("CreateOAuthApp", "app.oauth.save_app.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateOAuthApp", "app.oauth.save_app.existing.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("CreateOAuthApp", "app.oauth.save_app.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateOAuthApp", "app.oauth.save_app.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -67,9 +67,9 @@ func (a *App) GetOAuthApp(appID string) (*model.OAuthApp, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetOAuthApp", "app.oauth.get_app.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetOAuthApp", "app.oauth.get_app.find.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetOAuthApp", "app.oauth.get_app.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetOAuthApp", "app.oauth.get_app.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -94,9 +94,9 @@ func (a *App) UpdateOAuthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthAp case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("UpdateOAuthApp", "app.oauth.update_app.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpdateOAuthApp", "app.oauth.update_app.find.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("UpdateOAuthApp", "app.oauth.update_app.updating.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateOAuthApp", "app.oauth.update_app.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -109,7 +109,7 @@ func (a *App) DeleteOAuthApp(appID string) *model.AppError { } if err := a.Srv().Store.OAuth().DeleteApp(appID); err != nil { - return model.NewAppError("DeleteOAuthApp", "app.oauth.delete_app.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteOAuthApp", "app.oauth.delete_app.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().InvalidateAllCaches(); err != nil { @@ -126,7 +126,7 @@ func (a *App) GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppErro oauthApps, err := a.Srv().Store.OAuth().GetApps(page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetOAuthApps", "app.oauth.get_apps.find.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetOAuthApps", "app.oauth.get_apps.find.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return oauthApps, nil @@ -139,7 +139,7 @@ func (a *App) GetOAuthAppsByCreator(userID string, page, perPage int) ([]*model. oauthApps, err := a.Srv().Store.OAuth().GetAppByUser(userID, page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetOAuthAppsByCreator", "app.oauth.get_app_by_user.find.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetOAuthAppsByCreator", "app.oauth.get_app_by_user.find.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return oauthApps, nil @@ -186,9 +186,9 @@ func (a *App) AllowOAuthAppAccessToUser(userID string, authRequest *model.Author var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return "", model.NewAppError("AllowOAuthAppAccessToUser", "app.oauth.get_app.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return "", model.NewAppError("AllowOAuthAppAccessToUser", "app.oauth.get_app.find.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return "", model.NewAppError("AllowOAuthAppAccessToUser", "app.oauth.get_app.finding.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return "", model.NewAppError("AllowOAuthAppAccessToUser", "app.oauth.get_app.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -458,7 +458,7 @@ func (a *App) GetAuthorizedAppsForUser(userID string, page, perPage int) ([]*mod apps, err := a.Srv().Store.OAuth().GetAuthorizedApps(userID, page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetAuthorizedAppsForUser", "app.oauth.get_apps.find.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAuthorizedAppsForUser", "app.oauth.get_apps.find.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for k, a := range apps { @@ -477,7 +477,7 @@ func (a *App) DeauthorizeOAuthAppForUser(userID, appID string) *model.AppError { // Revoke app sessions accessData, err := a.Srv().Store.OAuth().GetAccessDataByUserForApp(userID, appID) if err != nil { - return model.NewAppError("DeauthorizeOAuthAppForUser", "app.oauth.get_access_data_by_user_for_app.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeauthorizeOAuthAppForUser", "app.oauth.get_access_data_by_user_for_app.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, ad := range accessData { @@ -486,13 +486,13 @@ func (a *App) DeauthorizeOAuthAppForUser(userID, appID string) *model.AppError { } if err := a.Srv().Store.OAuth().RemoveAccessData(ad.Token); err != nil { - return model.NewAppError("DeauthorizeOAuthAppForUser", "app.oauth.remove_access_data.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeauthorizeOAuthAppForUser", "app.oauth.remove_access_data.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } // Deauthorize the app if err := a.Srv().Store.Preference().Delete(userID, model.PreferenceCategoryAuthorizedOAuthApp, appID); err != nil { - return model.NewAppError("DeauthorizeOAuthAppForUser", "app.preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeauthorizeOAuthAppForUser", "app.preference.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -511,9 +511,9 @@ func (a *App) RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *m case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("RegenerateOAuthAppSecret", "app.oauth.update_app.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("RegenerateOAuthAppSecret", "app.oauth.update_app.find.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("RegenerateOAuthAppSecret", "app.oauth.update_app.updating.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("RegenerateOAuthAppSecret", "app.oauth.update_app.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -524,11 +524,11 @@ func (a *App) RevokeAccessToken(token string) *model.AppError { if err := a.ch.srv.userService.RevokeAccessToken(token); err != nil { switch { case errors.Is(err, users.GetTokenError): - return model.NewAppError("RevokeAccessToken", "api.oauth.revoke_access_token.get.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("RevokeAccessToken", "api.oauth.revoke_access_token.get.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.Is(err, users.DeleteTokenError): - return model.NewAppError("RevokeAccessToken", "api.oauth.revoke_access_token.del_token.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeAccessToken", "api.oauth.revoke_access_token.del_token.app_error", nil, "", http.StatusInternalServerError).Wrap(err) case errors.Is(err, users.DeleteSessionError): - return model.NewAppError("RevokeAccessToken", "api.oauth.revoke_access_token.del_session.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeAccessToken", "api.oauth.revoke_access_token.del_session.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -586,7 +586,7 @@ func (a *App) LoginByOAuth(c *request.Context, service string, userData io.Reade authUser, err1 := provider.GetUserFromJSON(bytes.NewReader(buf.Bytes()), tokenUser) if err1 != nil { return nil, model.NewAppError("LoginByOAuth", "api.user.login_by_oauth.parse.app_error", - map[string]any{"Service": service}, err1.Error(), http.StatusBadRequest) + map[string]any{"Service": service}, "", http.StatusBadRequest).Wrap(err1) } if *authUser.AuthData == "" { @@ -637,7 +637,7 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email ssoUser, err1 := provider.GetUserFromJSON(userData, tokenUser) if err1 != nil { return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.parse.app_error", - map[string]any{"Service": service}, err1.Error(), http.StatusBadRequest) + map[string]any{"Service": service}, "", http.StatusBadRequest).Wrap(err1) } if *ssoUser.AuthData == "" { @@ -647,7 +647,7 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email user, nErr := a.Srv().Store.User().GetByEmail(email) if nErr != nil { - return nil, model.NewAppError("CompleteSwitchWithOAuth", MissingAccountError, nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CompleteSwitchWithOAuth", MissingAccountError, nil, "", http.StatusInternalServerError).Wrap(nErr) } if err := a.RevokeAllSessions(user.Id); err != nil { @@ -658,9 +658,9 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email var invErr *store.ErrInvalidInput switch { case errors.As(nErr, &invErr): - return nil, model.NewAppError("importUser", "app.user.update_auth_data.email_exists.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("importUser", "app.user.update_auth_data.email_exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) default: - return nil, model.NewAppError("importUser", "app.user.update_auth_data.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("importUser", "app.user.update_auth_data.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -682,7 +682,7 @@ func (a *App) CreateOAuthStateToken(extra string) (*model.Token, *model.AppError case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("CreateOAuthStateToken", "app.recover.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateOAuthStateToken", "app.recover.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -692,7 +692,7 @@ func (a *App) CreateOAuthStateToken(extra string) (*model.Token, *model.AppError func (a *App) GetOAuthStateToken(token string) (*model.Token, *model.AppError) { mToken, err := a.Srv().Store.Token().GetByToken(token) if err != nil { - return nil, model.NewAppError("GetOAuthStateToken", "api.oauth.invalid_state_token.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetOAuthStateToken", "api.oauth.invalid_state_token.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if mToken.Type != model.TokenTypeOAuth { @@ -710,7 +710,7 @@ func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, servi sso, e2 := provider.GetSSOSettings(a.Config(), service) if e2 != nil { - return "", model.NewAppError("GetAuthorizationCode.GetSSOSettings", "api.user.get_authorization_code.endpoint.app_error", nil, e2.Error(), http.StatusNotImplemented) + return "", model.NewAppError("GetAuthorizationCode.GetSSOSettings", "api.user.get_authorization_code.endpoint.app_error", nil, "", http.StatusNotImplemented).Wrap(e2) } secure := false @@ -775,12 +775,12 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service sso, e2 := provider.GetSSOSettings(a.Config(), service) if e2 != nil { - return nil, "", nil, nil, model.NewAppError("AuthorizeOAuthUser.GetSSOSettings", "api.user.get_authorization_code.endpoint.app_error", nil, e2.Error(), http.StatusNotImplemented) + return nil, "", nil, nil, model.NewAppError("AuthorizeOAuthUser.GetSSOSettings", "api.user.get_authorization_code.endpoint.app_error", nil, "", http.StatusNotImplemented).Wrap(e2) } b, strErr := b64.StdEncoding.DecodeString(state) if strErr != nil { - return nil, "", nil, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.invalid_state.app_error", nil, strErr.Error(), http.StatusBadRequest) + return nil, "", nil, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.invalid_state.app_error", nil, "", http.StatusBadRequest).Wrap(strErr) } stateStr := string(b) @@ -835,7 +835,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service req, requestErr := http.NewRequest("POST", *sso.TokenEndpoint, strings.NewReader(p.Encode())) if requestErr != nil { - return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, requestErr.Error(), http.StatusInternalServerError) + return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, "", http.StatusInternalServerError).Wrap(requestErr) } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") @@ -843,7 +843,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service resp, err := a.HTTPService().MakeClient(true).Do(req) if err != nil { - return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } defer resp.Body.Close() @@ -870,13 +870,13 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service if ar.IdToken != "" { userFromToken, err = provider.GetUserFromIdToken(ar.IdToken) if err != nil { - return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } req, requestErr = http.NewRequest("GET", *sso.UserAPIEndpoint, strings.NewReader("")) if requestErr != nil { - return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.service.app_error", map[string]any{"Service": service}, requestErr.Error(), http.StatusInternalServerError) + return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.service.app_error", map[string]any{"Service": service}, "", http.StatusInternalServerError).Wrap(requestErr) } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") @@ -885,7 +885,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service resp, err = a.HTTPService().MakeClient(true).Do(req) if err != nil { - return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.service.app_error", map[string]any{"Service": service}, err.Error(), http.StatusInternalServerError) + return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.service.app_error", map[string]any{"Service": service}, "", http.StatusInternalServerError).Wrap(err) } else if resp.StatusCode != http.StatusOK { defer resp.Body.Close() diff --git a/app/oauth_test.go b/app/oauth_test.go index 57a394a710..0beff5b312 100644 --- a/app/oauth_test.go +++ b/app/oauth_test.go @@ -210,7 +210,7 @@ func TestAuthorizeOAuthUser(t *testing.T) { _, _, _, _, err := th.App.AuthorizeOAuthUser(nil, nil, model.ServiceGitlab, "", state, "") require.NotNil(t, err) assert.Equal(t, "api.oauth.invalid_state_token.app_error", err.Id) - assert.NotEqual(t, "", err.DetailedError) + assert.Error(t, err.Unwrap()) }) t.Run("with a stored token of the wrong type", func(t *testing.T) { diff --git a/app/onboarding.go b/app/onboarding.go index 31715507f3..f73cd68d84 100644 --- a/app/onboarding.go +++ b/app/onboarding.go @@ -21,7 +21,7 @@ func (a *App) markAdminOnboardingComplete(c *request.Context) *model.AppError { } if err := a.Srv().Store.System().SaveOrUpdate(&firstAdminCompleteSetupObj); err != nil { - return model.NewAppError("setFirstAdminCompleteSetup", "api.error_set_first_admin_complete_setup", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("setFirstAdminCompleteSetup", "api.error_set_first_admin_complete_setup", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -82,7 +82,7 @@ func (a *App) GetOnboarding() (*model.System, *model.AppError) { Value: "false", }, nil default: - return nil, model.NewAppError("getFirstAdminCompleteSetup", "api.error_get_first_admin_complete_setup", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getFirstAdminCompleteSetup", "api.error_get_first_admin_complete_setup", nil, "", http.StatusInternalServerError).Wrap(err) } } return firstAdminCompleteSetupObj, nil diff --git a/app/permissions.go b/app/permissions.go index 9c813b1f3f..999fdbd189 100644 --- a/app/permissions.go +++ b/app/permissions.go @@ -40,52 +40,52 @@ func (s *permissionsServiceWrapper) HasPermissionToChannel(askingUserID string, func (a *App) ResetPermissionsSystem() *model.AppError { // Reset all Teams to not have a scheme. if err := a.Srv().Store.Team().ResetAllTeamSchemes(); err != nil { - return model.NewAppError("ResetPermissionsSystem", "app.team.reset_all_team_schemes.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ResetPermissionsSystem", "app.team.reset_all_team_schemes.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Reset all Channels to not have a scheme. if err := a.Srv().Store.Channel().ResetAllChannelSchemes(); err != nil { - return model.NewAppError("ResetPermissionsSystem", "app.channel.reset_all_channel_schemes.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ResetPermissionsSystem", "app.channel.reset_all_channel_schemes.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Reset all Custom Role assignments to Users. if err := a.Srv().Store.User().ClearAllCustomRoleAssignments(); err != nil { - return model.NewAppError("ResetPermissionsSystem", "app.user.clear_all_custom_role_assignments.select.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ResetPermissionsSystem", "app.user.clear_all_custom_role_assignments.select.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Reset all Custom Role assignments to TeamMembers. if err := a.Srv().Store.Team().ClearAllCustomRoleAssignments(); err != nil { - return model.NewAppError("ResetPermissionsSystem", "app.team.clear_all_custom_role_assignments.select.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ResetPermissionsSystem", "app.team.clear_all_custom_role_assignments.select.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Reset all Custom Role assignments to ChannelMembers. if err := a.Srv().Store.Channel().ClearAllCustomRoleAssignments(); err != nil { - return model.NewAppError("ResetPermissionsSystem", "app.channel.clear_all_custom_role_assignments.select.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ResetPermissionsSystem", "app.channel.clear_all_custom_role_assignments.select.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Purge all schemes from the database. if err := a.Srv().Store.Scheme().PermanentDeleteAll(); err != nil { - return model.NewAppError("ResetPermissionsSystem", "app.scheme.permanent_delete_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ResetPermissionsSystem", "app.scheme.permanent_delete_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Purge all roles from the database. if err := a.Srv().Store.Role().PermanentDeleteAll(); err != nil { - return model.NewAppError("ResetPermissionsSystem", "app.role.permanent_delete_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ResetPermissionsSystem", "app.role.permanent_delete_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Remove the "System" table entry that marks the advanced permissions migration as done. if _, err := a.Srv().Store.System().PermanentDeleteByName(model.AdvancedPermissionsMigrationKey); err != nil { - return model.NewAppError("ResetPermissionSystem", "app.system.permanent_delete_by_name.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ResetPermissionSystem", "app.system.permanent_delete_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Remove the "System" table entry that marks the emoji permissions migration as done. if _, err := a.Srv().Store.System().PermanentDeleteByName(EmojisPermissionsMigrationKey); err != nil { - return model.NewAppError("ResetPermissionSystem", "app.system.permanent_delete_by_name.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ResetPermissionSystem", "app.system.permanent_delete_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Remove the "System" table entry that marks the guest roles permissions migration as done. if _, err := a.Srv().Store.System().PermanentDeleteByName(GuestRolesCreationMigrationKey); err != nil { - return model.NewAppError("ResetPermissionSystem", "app.system.permanent_delete_by_name.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ResetPermissionSystem", "app.system.permanent_delete_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Now that the permissions system has been reset, re-run the migration to reinitialise it. diff --git a/app/permissions_migrations.go b/app/permissions_migrations.go index dd927c586f..862a02b207 100644 --- a/app/permissions_migrations.go +++ b/app/permissions_migrations.go @@ -176,15 +176,15 @@ func (s *Server) doPermissionsMigration(key string, migrationMap permissionsMap, var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return model.NewAppError("doPermissionsMigration", "app.role.save.invalid_role.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("doPermissionsMigration", "app.role.save.invalid_role.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return model.NewAppError("doPermissionsMigration", "app.role.save.insert.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("doPermissionsMigration", "app.role.save.insert.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } } if err := s.Store.System().SaveOrUpdate(&model.System{Name: key, Value: "true"}); err != nil { - return model.NewAppError("doPermissionsMigration", "app.system.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("doPermissionsMigration", "app.system.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } diff --git a/app/platform/config.go b/app/platform/config.go index fc13aa3761..dbe0cbf85e 100644 --- a/app/platform/config.go +++ b/app/platform/config.go @@ -82,9 +82,9 @@ func (ps *PlatformService) UpdateConfig(f func(*model.Config)) { func (ps *PlatformService) SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bool) (*model.Config, *model.Config, *model.AppError) { oldCfg, newCfg, err := ps.configStore.Set(newCfg) if errors.Is(err, config.ErrReadOnlyConfiguration) { - return nil, nil, model.NewAppError("saveConfig", "ent.cluster.save_config.error", nil, err.Error(), http.StatusForbidden) + return nil, nil, model.NewAppError("saveConfig", "ent.cluster.save_config.error", nil, "", http.StatusForbidden).Wrap(err) } else if err != nil { - return nil, nil, model.NewAppError("saveConfig", "app.save_config.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("saveConfig", "app.save_config.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if ps.serviceConfig.StartMetrics && *ps.Config().MetricsSettings.Enable { diff --git a/app/plugin.go b/app/plugin.go index 2775eb0d86..35bb276b41 100644 --- a/app/plugin.go +++ b/app/plugin.go @@ -292,7 +292,7 @@ func (ch *Channels) syncPlugins() *model.AppError { availablePlugins, err := pluginsEnvironment.Available() if err != nil { - return model.NewAppError("SyncPlugins", "app.plugin.sync.read_local_folder.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SyncPlugins", "app.plugin.sync.read_local_folder.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } var wg sync.WaitGroup @@ -416,7 +416,7 @@ func (ch *Channels) enablePlugin(id string) *model.AppError { availablePlugins, err := pluginsEnvironment.Available() if err != nil { - return model.NewAppError("EnablePlugin", "app.plugin.config.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("EnablePlugin", "app.plugin.config.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } id = strings.ToLower(id) @@ -442,7 +442,7 @@ func (ch *Channels) enablePlugin(id string) *model.AppError { if err.Id == "ent.cluster.save_config.error" { return model.NewAppError("EnablePlugin", "app.plugin.cluster.save_config.app_error", nil, "", http.StatusInternalServerError) } - return model.NewAppError("EnablePlugin", "app.plugin.config.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("EnablePlugin", "app.plugin.config.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -467,7 +467,7 @@ func (ch *Channels) disablePlugin(id string) *model.AppError { availablePlugins, err := pluginsEnvironment.Available() if err != nil { - return model.NewAppError("DisablePlugin", "app.plugin.config.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DisablePlugin", "app.plugin.config.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } id = strings.ToLower(id) @@ -491,7 +491,7 @@ func (ch *Channels) disablePlugin(id string) *model.AppError { // This call will implicitly invoke SyncPluginsActiveState which will deactivate disabled plugins. if _, _, err := ch.cfgSvc.SaveConfig(ch.cfgSvc.Config(), true); err != nil { - return model.NewAppError("DisablePlugin", "app.plugin.config.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DisablePlugin", "app.plugin.config.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -519,7 +519,7 @@ func (a *App) GetPlugins() (*model.PluginsResponse, *model.AppError) { availablePlugins, err := pluginsEnvironment.Available() if err != nil { - return nil, model.NewAppError("GetPlugins", "app.plugin.get_plugins.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPlugins", "app.plugin.get_plugins.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } resp := &model.PluginsResponse{Active: []*model.PluginInfo{}, Inactive: []*model.PluginInfo{}} for _, plugin := range availablePlugins { @@ -616,7 +616,7 @@ func (ch *Channels) getRemoteMarketplacePlugin(pluginID, version string) (*model ch.srv.HTTPService(), ) if err != nil { - return nil, model.NewAppError("GetMarketplacePlugin", "app.plugin.marketplace_client.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetMarketplacePlugin", "app.plugin.marketplace_client.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } filter := ch.getBaseMarketplaceFilter() @@ -629,7 +629,7 @@ func (ch *Channels) getRemoteMarketplacePlugin(pluginID, version string) (*model plugin, err = marketplaceClient.GetLatestPlugin(filter) } if err != nil { - return nil, model.NewAppError("GetMarketplacePlugin", "app.plugin.marketplace_plugins.not_found.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetMarketplacePlugin", "app.plugin.marketplace_plugins.not_found.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return plugin, nil @@ -648,7 +648,7 @@ func (a *App) getRemotePlugins() (map[string]*model.MarketplacePlugin, *model.Ap a.HTTPService(), ) if err != nil { - return nil, model.NewAppError("getRemotePlugins", "app.plugin.marketplace_client.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getRemotePlugins", "app.plugin.marketplace_client.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } filter := a.getBaseMarketplaceFilter() @@ -657,7 +657,7 @@ func (a *App) getRemotePlugins() (map[string]*model.MarketplacePlugin, *model.Ap marketplacePlugins, err := marketplaceClient.GetPlugins(filter) if err != nil { - return nil, model.NewAppError("getRemotePlugins", "app.plugin.marketplace_client.failed_to_fetch", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getRemotePlugins", "app.plugin.marketplace_client.failed_to_fetch", nil, "", http.StatusInternalServerError).Wrap(err) } for _, p := range marketplacePlugins { @@ -701,13 +701,13 @@ func (a *App) mergePrepackagedPlugins(remoteMarketplacePlugins map[string]*model // If available in the marketplace, only overwrite if newer. prepackagedVersion, err := semver.Parse(prepackaged.Manifest.Version) if err != nil { - return model.NewAppError("mergePrepackagedPlugins", "app.plugin.invalid_version.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("mergePrepackagedPlugins", "app.plugin.invalid_version.app_error", nil, "", http.StatusBadRequest).Wrap(err) } marketplacePlugin := remoteMarketplacePlugins[prepackaged.Manifest.Id] marketplaceVersion, err := semver.Parse(marketplacePlugin.Manifest.Version) if err != nil { - return model.NewAppError("mergePrepackagedPlugins", "app.plugin.invalid_version.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("mergePrepackagedPlugins", "app.plugin.invalid_version.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if prepackagedVersion.GT(marketplaceVersion) { @@ -727,7 +727,7 @@ func (a *App) mergeLocalPlugins(remoteMarketplacePlugins map[string]*model.Marke localPlugins, err := pluginsEnvironment.Available() if err != nil { - return model.NewAppError("GetMarketplacePlugins", "app.plugin.config.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("GetMarketplacePlugins", "app.plugin.config.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, plugin := range localPlugins { @@ -876,7 +876,7 @@ func (ch *Channels) notifyPluginEnabled(manifest *model.Manifest) error { func (ch *Channels) getPluginsFromFolder() (map[string]*pluginSignaturePath, *model.AppError) { fileStorePaths, appErr := ch.srv.listDirectory(fileStorePluginFolder, false) if appErr != nil { - return nil, model.NewAppError("getPluginsFromDir", "app.plugin.sync.list_filestore.app_error", nil, appErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("getPluginsFromDir", "app.plugin.sync.list_filestore.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr) } return ch.getPluginsFromFilePaths(fileStorePaths), nil diff --git a/app/plugin_api.go b/app/plugin_api.go index f2afc5e7ce..ceb7e6ea2b 100644 --- a/app/plugin_api.go +++ b/app/plugin_api.go @@ -289,11 +289,11 @@ func (api *PluginAPI) CreateSession(session *model.Session) (*model.Session, *mo func (api *PluginAPI) ExtendSessionExpiry(sessionID string, expiresAt int64) *model.AppError { session, err := api.app.ch.srv.userService.GetSessionByID(sessionID) if err != nil { - return model.NewAppError("extendSessionExpiry", "app.session.get_sessions.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("extendSessionExpiry", "app.session.get_sessions.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := api.app.ch.srv.userService.ExtendSessionExpiry(session, expiresAt); err != nil { - return model.NewAppError("extendSessionExpiry", "app.session.extend_session_expiry.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("extendSessionExpiry", "app.session.extend_session_expiry.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -852,7 +852,7 @@ func (api *PluginAPI) SendMail(to, subject, htmlBody string) *model.AppError { } if err := api.app.Srv().EmailService.SendNotificationMail(to, subject, htmlBody); err != nil { - return model.NewAppError("SendMail", "plugin_api.send_mail.missing_htmlbody", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SendMail", "plugin_api.send_mail.missing_htmlbody", nil, "", http.StatusInternalServerError).Wrap(err) } return nil diff --git a/app/plugin_install.go b/app/plugin_install.go index 12eb1f3046..fa076df3c4 100644 --- a/app/plugin_install.go +++ b/app/plugin_install.go @@ -152,14 +152,14 @@ func (ch *Channels) installPlugin(pluginFile, signature io.ReadSeeker, installat if signature != nil { signature.Seek(0, 0) if _, appErr = ch.srv.writeFile(signature, getSignatureStorePath(manifest.Id)); appErr != nil { - return nil, model.NewAppError("saveSignature", "app.plugin.store_signature.app_error", nil, appErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("saveSignature", "app.plugin.store_signature.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr) } } // Store bundle in the file store to allow access from other servers. pluginFile.Seek(0, 0) if _, appErr := ch.srv.writeFile(pluginFile, getBundleStorePath(manifest.Id)); appErr != nil { - return nil, model.NewAppError("uploadPlugin", "app.plugin.store_bundle.app_error", nil, appErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("uploadPlugin", "app.plugin.store_bundle.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr) } ch.notifyClusterPluginEvent( @@ -216,23 +216,23 @@ func (ch *Channels) InstallMarketplacePlugin(request *model.InstallMarketplacePl var err error prepackagedVersion, err = semver.Parse(prepackagedPlugin.Manifest.Version) if err != nil { - return nil, model.NewAppError("InstallMarketplacePlugin", "app.plugin.invalid_version.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("InstallMarketplacePlugin", "app.plugin.invalid_version.app_error", nil, "", http.StatusBadRequest).Wrap(err) } } marketplaceVersion, err := semver.Parse(plugin.Manifest.Version) if err != nil { - return nil, model.NewAppError("InstallMarketplacePlugin", "app.prepackged-plugin.invalid_version.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("InstallMarketplacePlugin", "app.prepackged-plugin.invalid_version.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if prepackagedVersion.LT(marketplaceVersion) { // Always true if no prepackaged plugin was found downloadedPluginBytes, err := ch.srv.downloadFromURL(plugin.DownloadURL) if err != nil { - 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, "", http.StatusInternalServerError).Wrap(err) } signature, err := plugin.DecodeSignature() if err != nil { - return nil, model.NewAppError("InstallMarketplacePlugin", "app.plugin.signature_decode.app_error", nil, err.Error(), http.StatusNotImplemented) + return nil, model.NewAppError("InstallMarketplacePlugin", "app.plugin.signature_decode.app_error", nil, "", http.StatusNotImplemented).Wrap(err) } pluginFile = bytes.NewReader(downloadedPluginBytes) signatureFile = signature @@ -280,7 +280,7 @@ func (ch *Channels) installPluginLocally(pluginFile, signature io.ReadSeeker, in tmpDir, err := os.MkdirTemp("", "plugintmp") if err != nil { - return nil, model.NewAppError("installPluginLocally", "app.plugin.filesystem.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("installPluginLocally", "app.plugin.filesystem.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } defer os.RemoveAll(tmpDir) @@ -300,12 +300,12 @@ func (ch *Channels) installPluginLocally(pluginFile, signature io.ReadSeeker, in func extractPlugin(pluginFile io.ReadSeeker, extractDir string) (*model.Manifest, string, *model.AppError) { pluginFile.Seek(0, 0) if err := extractTarGz(pluginFile, extractDir); err != nil { - return nil, "", model.NewAppError("extractPlugin", "app.plugin.extract.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, "", model.NewAppError("extractPlugin", "app.plugin.extract.app_error", nil, "", http.StatusBadRequest).Wrap(err) } dir, err := os.ReadDir(extractDir) if err != nil { - return nil, "", model.NewAppError("extractPlugin", "app.plugin.filesystem.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, "", model.NewAppError("extractPlugin", "app.plugin.filesystem.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(dir) == 1 && dir[0].IsDir() { @@ -314,7 +314,7 @@ func extractPlugin(pluginFile io.ReadSeeker, extractDir string) (*model.Manifest manifest, _, err := model.FindManifest(extractDir) if err != nil { - return nil, "", model.NewAppError("extractPlugin", "app.plugin.manifest.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, "", model.NewAppError("extractPlugin", "app.plugin.manifest.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if !model.IsValidPluginId(manifest.Id) { @@ -332,7 +332,7 @@ func (ch *Channels) installExtractedPlugin(manifest *model.Manifest, fromPluginD bundles, err := pluginsEnvironment.Available() if err != nil { - return nil, model.NewAppError("installExtractedPlugin", "app.plugin.install.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("installExtractedPlugin", "app.plugin.install.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Check for plugins installed with the same ID. @@ -380,20 +380,20 @@ func (ch *Channels) installExtractedPlugin(manifest *model.Manifest, fromPluginD pluginPath := filepath.Join(*ch.cfgSvc.Config().PluginSettings.Directory, manifest.Id) err = utils.CopyDir(fromPluginDir, pluginPath) if err != nil { - return nil, model.NewAppError("installExtractedPlugin", "app.plugin.mvdir.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("installExtractedPlugin", "app.plugin.mvdir.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Flag plugin locally as managed by the filestore. f, err := os.Create(filepath.Join(pluginPath, managedPluginFileName)) if err != nil { - return nil, model.NewAppError("installExtractedPlugin", "app.plugin.flag_managed.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("installExtractedPlugin", "app.plugin.flag_managed.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } f.Close() if manifest.HasWebapp() { updatedManifest, err := pluginsEnvironment.UnpackWebappBundle(manifest.Id) if err != nil { - return nil, model.NewAppError("installExtractedPlugin", "app.plugin.webapp_bundle.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("installExtractedPlugin", "app.plugin.webapp_bundle.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } manifest = updatedManifest } @@ -407,7 +407,7 @@ func (ch *Channels) installExtractedPlugin(manifest *model.Manifest, fromPluginD updatedManifest, _, err := pluginsEnvironment.Activate(manifest.Id) if err != nil { - return nil, model.NewAppError("installExtractedPlugin", "app.plugin.restart.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("installExtractedPlugin", "app.plugin.restart.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } else if updatedManifest == nil { return nil, model.NewAppError("installExtractedPlugin", "app.plugin.restart.app_error", nil, "failed to activate plugin: plugin already active", http.StatusInternalServerError) } @@ -432,13 +432,13 @@ func (ch *Channels) RemovePlugin(id string) *model.AppError { storePluginFileName := getBundleStorePath(id) bundleExist, err := ch.srv.fileExists(storePluginFileName) if err != nil { - return model.NewAppError("removePlugin", "app.plugin.remove_bundle.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("removePlugin", "app.plugin.remove_bundle.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if !bundleExist { return nil } if err = ch.srv.removeFile(storePluginFileName); err != nil { - return model.NewAppError("removePlugin", "app.plugin.remove_bundle.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("removePlugin", "app.plugin.remove_bundle.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err = ch.removeSignature(id); err != nil { mlog.Warn("Can't remove signature", mlog.Err(err)) @@ -470,7 +470,7 @@ func (ch *Channels) removePluginLocally(id string) *model.AppError { plugins, err := pluginsEnvironment.Available() if err != nil { - return model.NewAppError("removePlugin", "app.plugin.deactivate.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("removePlugin", "app.plugin.deactivate.app_error", nil, "", http.StatusBadRequest).Wrap(err) } var manifest *model.Manifest @@ -492,7 +492,7 @@ func (ch *Channels) removePluginLocally(id string) *model.AppError { ch.unregisterPluginCommands(id) if err := os.RemoveAll(pluginPath); err != nil { - return model.NewAppError("removePlugin", "app.plugin.remove.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("removePlugin", "app.plugin.remove.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -502,14 +502,14 @@ func (ch *Channels) removeSignature(pluginID string) *model.AppError { filePath := getSignatureStorePath(pluginID) exists, err := ch.srv.fileExists(filePath) if err != nil { - return model.NewAppError("removeSignature", "app.plugin.remove_bundle.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("removeSignature", "app.plugin.remove_bundle.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if !exists { mlog.Debug("no plugin signature to remove", mlog.String("plugin_id", pluginID)) return nil } if err = ch.srv.removeFile(filePath); err != nil { - return model.NewAppError("removeSignature", "app.plugin.remove_bundle.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("removeSignature", "app.plugin.remove_bundle.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } diff --git a/app/plugin_key_value_store.go b/app/plugin_key_value_store.go index 23419a7ff6..961932ea30 100644 --- a/app/plugin_key_value_store.go +++ b/app/plugin_key_value_store.go @@ -67,7 +67,7 @@ func (s *Server) setPluginKeyWithOptions(pluginID string, key string, value []by case errors.As(err, &appErr): return false, appErr default: - return false, model.NewAppError("SetPluginKeyWithOptions", "app.plugin_store.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return false, model.NewAppError("SetPluginKeyWithOptions", "app.plugin_store.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -97,7 +97,7 @@ func (a *App) CompareAndDeletePluginKey(pluginID string, key string, oldValue [] case errors.As(err, &appErr): return deleted, appErr default: - return false, model.NewAppError("CompareAndDeletePluginKey", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return false, model.NewAppError("CompareAndDeletePluginKey", "app.plugin_store.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -114,7 +114,7 @@ func (s *Server) getPluginKey(pluginID string, key string) ([]byte, *model.AppEr return kv.Value, nil } else if nfErr := new(store.ErrNotFound); !errors.As(err, &nfErr) { mlog.Error("Failed to query plugin key value", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err)) - return nil, model.NewAppError("GetPluginKey", "app.plugin_store.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPluginKey", "app.plugin_store.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Lookup using the hashed version of the key for keys written prior to v5.6. @@ -122,7 +122,7 @@ func (s *Server) getPluginKey(pluginID string, key string) ([]byte, *model.AppEr return kv.Value, nil } else if nfErr := new(store.ErrNotFound); !errors.As(err, &nfErr) { mlog.Error("Failed to query plugin key value using hashed key", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err)) - return nil, model.NewAppError("GetPluginKey", "app.plugin_store.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPluginKey", "app.plugin_store.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil, nil @@ -135,13 +135,13 @@ func (a *App) GetPluginKey(pluginID string, key string) ([]byte, *model.AppError func (s *Server) deletePluginKey(pluginID string, key string) *model.AppError { if err := s.Store.Plugin().Delete(pluginID, getKeyHash(key)); err != nil { mlog.Error("Failed to delete plugin key value", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err)) - return model.NewAppError("DeletePluginKey", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeletePluginKey", "app.plugin_store.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Also delete the key without hashing if err := s.Store.Plugin().Delete(pluginID, key); err != nil { mlog.Error("Failed to delete plugin key value using hashed key", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err)) - return model.NewAppError("DeletePluginKey", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeletePluginKey", "app.plugin_store.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -154,7 +154,7 @@ func (a *App) DeletePluginKey(pluginID string, key string) *model.AppError { func (a *App) DeleteAllKeysForPlugin(pluginID string) *model.AppError { if err := a.Srv().Store.Plugin().DeleteAllForPlugin(pluginID); err != nil { mlog.Error("Failed to delete all plugin key values", mlog.String("plugin_id", pluginID), mlog.Err(err)) - return model.NewAppError("DeleteAllKeysForPlugin", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteAllKeysForPlugin", "app.plugin_store.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -167,7 +167,7 @@ func (a *App) DeleteAllExpiredPluginKeys() *model.AppError { if err := a.Srv().Store.Plugin().DeleteAllExpired(); err != nil { mlog.Error("Failed to delete all expired plugin key values", mlog.Err(err)) - return model.NewAppError("DeleteAllExpiredPluginKeys", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteAllExpiredPluginKeys", "app.plugin_store.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -178,7 +178,7 @@ func (s *Server) listPluginKeys(pluginID string, page, perPage int) ([]string, * if err != nil { mlog.Error("Failed to list plugin key values", mlog.Int("page", page), mlog.Int("perPage", perPage), mlog.Err(err)) - return nil, model.NewAppError("ListPluginKeys", "app.plugin_store.list.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ListPluginKeys", "app.plugin_store.list.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return data, nil diff --git a/app/plugin_signature.go b/app/plugin_signature.go index bedb6946a1..0903aa08fc 100644 --- a/app/plugin_signature.go +++ b/app/plugin_signature.go @@ -26,7 +26,7 @@ func (a *App) GetPublicKey(name string) ([]byte, *model.AppError) { func (s *Server) getPublicKey(name string) ([]byte, *model.AppError) { data, err := s.platform.GetConfigFile(name) if err != nil { - return nil, model.NewAppError("GetPublicKey", "app.plugin.get_public_key.get_file.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPublicKey", "app.plugin.get_public_key.get_file.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return data, nil } @@ -38,11 +38,11 @@ func (a *App) AddPublicKey(name string, key io.Reader) *model.AppError { } data, err := io.ReadAll(key) if err != nil { - return model.NewAppError("AddPublicKey", "app.plugin.write_file.read.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("AddPublicKey", "app.plugin.write_file.read.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } err = a.Srv().platform.SetConfigFile(name, data) if err != nil { - return model.NewAppError("AddPublicKey", "app.plugin.write_file.saving.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("AddPublicKey", "app.plugin.write_file.saving.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.UpdateConfig(func(cfg *model.Config) { @@ -61,7 +61,7 @@ func (a *App) DeletePublicKey(name string) *model.AppError { } filename := filepath.Base(name) if err := a.Srv().platform.RemoveConfigFile(filename); err != nil { - return model.NewAppError("DeletePublicKey", "app.plugin.delete_public_key.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeletePublicKey", "app.plugin.delete_public_key.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.UpdateConfig(func(cfg *model.Config) { diff --git a/app/plugin_statuses.go b/app/plugin_statuses.go index 540ab7c4ac..ad71925967 100644 --- a/app/plugin_statuses.go +++ b/app/plugin_statuses.go @@ -18,7 +18,7 @@ func (ch *Channels) GetPluginStatus(id string) (*model.PluginStatus, *model.AppE pluginStatuses, err := pluginsEnvironment.Statuses() if err != nil { - return nil, model.NewAppError("GetPluginStatus", "app.plugin.get_statuses.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPluginStatus", "app.plugin.get_statuses.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, status := range pluginStatuses { @@ -49,7 +49,7 @@ func (ch *Channels) GetPluginStatuses() (model.PluginStatuses, *model.AppError) pluginStatuses, err := pluginsEnvironment.Statuses() if err != nil { - return nil, model.NewAppError("GetPluginStatuses", "app.plugin.get_statuses.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPluginStatuses", "app.plugin.get_statuses.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Add our cluster ID @@ -83,7 +83,7 @@ func (ch *Channels) getClusterPluginStatuses() (model.PluginStatuses, *model.App if ch.srv.Cluster != nil && *ch.cfgSvc.Config().ClusterSettings.Enable { clusterPluginStatuses, err := ch.srv.Cluster.GetPluginStatuses() if err != nil { - return nil, model.NewAppError("GetClusterPluginStatuses", "app.plugin.get_cluster_plugin_statuses.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetClusterPluginStatuses", "app.plugin.get_cluster_plugin_statuses.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } pluginStatuses = append(pluginStatuses, clusterPluginStatuses...) diff --git a/app/post.go b/app/post.go index 3abd81a0a8..dd5e2c31ba 100644 --- a/app/post.go +++ b/app/post.go @@ -50,7 +50,7 @@ func (a *App) CreatePostAsUser(c request.CTX, post *model.Post, currentSessionId // Check that channel has not been deleted channel, errCh := a.Srv().Store.Channel().Get(post.ChannelId, true) if errCh != nil { - err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]any{"Name": "post.channel_id"}, errCh.Error(), http.StatusBadRequest) + err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]any{"Name": "post.channel_id"}, "", http.StatusBadRequest).Wrap(errCh) return nil, err } @@ -101,9 +101,9 @@ func (a *App) CreatePostMissingChannel(c request.CTX, post *model.Post, triggerW var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("CreatePostMissingChannel", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("CreatePostMissingChannel", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("CreatePostMissingChannel", "app.channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreatePostMissingChannel", "app.channel.get.find.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -144,7 +144,7 @@ func (a *App) deduplicateCreatePost(post *model.Post) (foundPost *model.Post, er // client, making the API call feel idempotent. actualPost, err := a.GetSinglePost(postID, false) if err != nil { - return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.failed_to_get", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.failed_to_get", nil, "", http.StatusInternalServerError).Wrap(err) } mlog.Debug("Deduplicated create post", mlog.String("post_id", actualPost.Id), mlog.String("pending_post_id", post.PendingPostId)) @@ -193,9 +193,9 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("CreatePost", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("CreatePost", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("CreatePost", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreatePost", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -300,9 +300,9 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel case errors.As(nErr, &appErr): return nil, appErr case errors.As(nErr, &invErr): - return nil, model.NewAppError("CreatePost", "app.post.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreatePost", "app.post.save.existing.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) default: - return nil, model.NewAppError("CreatePost", "app.post.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreatePost", "app.post.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -397,7 +397,7 @@ func (a *App) attachFilesToPost(post *model.Post) *model.AppError { post.FileIds = attachedIds if _, err := a.Srv().Store.Post().Overwrite(post); err != nil { - return model.NewAppError("attachFilesToPost", "app.post.overwrite.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("attachFilesToPost", "app.post.overwrite.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -416,7 +416,7 @@ func (a *App) FillInPostProps(c request.CTX, post *model.Post, channel *model.Ch if channel == nil { postChannel, err := a.Srv().Store.Channel().GetForPost(post.Id) if err != nil { - return model.NewAppError("FillInPostProps", "api.context.invalid_param.app_error", map[string]any{"Name": "post.channel_id"}, err.Error(), http.StatusBadRequest) + return model.NewAppError("FillInPostProps", "api.context.invalid_param.app_error", map[string]any{"Name": "post.channel_id"}, "", http.StatusBadRequest).Wrap(err) } channel = postChannel } @@ -573,11 +573,11 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool) var invErr *store.ErrInvalidInput switch { case errors.As(nErr, &invErr): - return nil, model.NewAppError("UpdatePost", "app.post.get.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpdatePost", "app.post.get.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &nfErr): - return nil, model.NewAppError("UpdatePost", "app.post.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("UpdatePost", "app.post.get.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("UpdatePost", "app.post.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdatePost", "app.post.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } oldPost := postLists.Posts[post.Id] @@ -662,7 +662,7 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool) case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("UpdatePost", "app.post.update.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdatePost", "app.post.update.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -687,13 +687,13 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool) rpost, nErr = a.addPostPreviewProp(rpost) if nErr != nil { - return nil, model.NewAppError("UpdatePost", "app.post.update.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdatePost", "app.post.update.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } message := model.NewWebSocketEvent(model.WebsocketEventPostEdited, "", rpost.ChannelId, "", nil) postJSON, jsonErr := rpost.ToJSON() if jsonErr != nil { - return nil, model.NewAppError("UpdatePost", "app.post.marshal.app_error", nil, jsonErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdatePost", "app.post.marshal.app_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr) } message.Add("post", postJSON) @@ -808,9 +808,9 @@ func (a *App) GetPostsPage(options model.GetPostsOptions) (*model.PostList, *mod var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("GetPostsPage", "app.post.get_posts.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPostsPage", "app.post.get_posts.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("GetPostsPage", "app.post.get_root_posts.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPostsPage", "app.post.get_root_posts.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -828,9 +828,9 @@ func (a *App) GetPosts(channelID string, offset int, limit int) (*model.PostList var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("GetPosts", "app.post.get_posts.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPosts", "app.post.get_posts.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("GetPosts", "app.post.get_root_posts.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPosts", "app.post.get_root_posts.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -848,7 +848,7 @@ func (a *App) GetPostsEtag(channelID string, collapsedThreads bool) string { func (a *App) GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList, *model.AppError) { postList, err := a.Srv().Store.Post().GetPostsSince(options, true, a.Config().GetSanitizeOptions()) if err != nil { - return nil, model.NewAppError("GetPostsSince", "app.post.get_posts_since.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPostsSince", "app.post.get_posts_since.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if appErr := a.filterInaccessiblePosts(postList, filterPostOptions{assumeSortedCreatedAt: true}); appErr != nil { @@ -864,9 +864,9 @@ func (a *App) GetSinglePost(postID string, includeDeleted bool) (*model.Post, *m var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetSinglePost", "app.post.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetSinglePost", "app.post.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetSinglePost", "app.post.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetSinglePost", "app.post.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -888,11 +888,11 @@ func (a *App) GetPostThread(postID string, opts model.GetPostsOptions, userID st var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("GetPostThread", "app.post.get.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPostThread", "app.post.get.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &nfErr): - return nil, model.NewAppError("GetPostThread", "app.post.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetPostThread", "app.post.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetPostThread", "app.post.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPostThread", "app.post.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -914,7 +914,7 @@ func (a *App) GetPostThread(postID string, opts model.GetPostsOptions, userID st func (a *App) GetFlaggedPosts(userID string, offset int, limit int) (*model.PostList, *model.AppError) { postList, err := a.Srv().Store.Post().GetFlaggedPosts(userID, offset, limit) if err != nil { - return nil, model.NewAppError("GetFlaggedPosts", "app.post.get_flagged_posts.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetFlaggedPosts", "app.post.get_flagged_posts.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if appErr := a.filterInaccessiblePosts(postList, filterPostOptions{assumeSortedCreatedAt: true}); appErr != nil { @@ -927,7 +927,7 @@ func (a *App) GetFlaggedPosts(userID string, offset int, limit int) (*model.Post func (a *App) GetFlaggedPostsForTeam(userID, teamID string, offset int, limit int) (*model.PostList, *model.AppError) { postList, err := a.Srv().Store.Post().GetFlaggedPostsForTeam(userID, teamID, offset, limit) if err != nil { - return nil, model.NewAppError("GetFlaggedPostsForTeam", "app.post.get_flagged_posts.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetFlaggedPostsForTeam", "app.post.get_flagged_posts.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if appErr := a.filterInaccessiblePosts(postList, filterPostOptions{assumeSortedCreatedAt: true}); appErr != nil { @@ -940,7 +940,7 @@ func (a *App) GetFlaggedPostsForTeam(userID, teamID string, offset int, limit in func (a *App) GetFlaggedPostsForChannel(userID, channelID string, offset int, limit int) (*model.PostList, *model.AppError) { postList, err := a.Srv().Store.Post().GetFlaggedPostsForChannel(userID, channelID, offset, limit) if err != nil { - return nil, model.NewAppError("GetFlaggedPostsForChannel", "app.post.get_flagged_posts.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetFlaggedPostsForChannel", "app.post.get_flagged_posts.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if appErr := a.filterInaccessiblePosts(postList, filterPostOptions{assumeSortedCreatedAt: true}); appErr != nil { @@ -957,11 +957,11 @@ func (a *App) GetPermalinkPost(c request.CTX, postID string, userID string) (*mo var invErr *store.ErrInvalidInput switch { case errors.As(nErr, &invErr): - return nil, model.NewAppError("GetPermalinkPost", "app.post.get.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPermalinkPost", "app.post.get.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &nfErr): - return nil, model.NewAppError("GetPermalinkPost", "app.post.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetPermalinkPost", "app.post.get.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("GetPermalinkPost", "app.post.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPermalinkPost", "app.post.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -992,9 +992,9 @@ func (a *App) GetPostsBeforePost(options model.GetPostsOptions) (*model.PostList var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("GetPostsBeforePost", "app.post.get_posts_around.get.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPostsBeforePost", "app.post.get_posts_around.get.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("GetPostsBeforePost", "app.post.get_posts_around.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPostsBeforePost", "app.post.get_posts_around.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1020,9 +1020,9 @@ func (a *App) GetPostsAfterPost(options model.GetPostsOptions) (*model.PostList, var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("GetPostsAfterPost", "app.post.get_posts_around.get.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPostsAfterPost", "app.post.get_posts_around.get.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("GetPostsAfterPost", "app.post.get_posts_around.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPostsAfterPost", "app.post.get_posts_around.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1056,9 +1056,9 @@ func (a *App) GetPostsAroundPost(before bool, options model.GetPostsOptions) (*m var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("GetPostsAroundPost", "app.post.get_posts_around.get.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPostsAroundPost", "app.post.get_posts_around.get.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("GetPostsAroundPost", "app.post.get_posts_around.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPostsAroundPost", "app.post.get_posts_around.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1081,7 +1081,7 @@ func (a *App) GetPostsAroundPost(before bool, options model.GetPostsOptions) (*m func (a *App) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, *model.AppError) { post, err := a.Srv().Store.Post().GetPostAfterTime(channelID, time, collapsedThreads) if err != nil { - return nil, model.NewAppError("GetPostAfterTime", "app.post.get_post_after_time.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetPostAfterTime", "app.post.get_post_after_time.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return post, nil @@ -1090,7 +1090,7 @@ func (a *App) GetPostAfterTime(channelID string, time int64, collapsedThreads bo func (a *App) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError) { postID, err := a.Srv().Store.Post().GetPostIdAfterTime(channelID, time, collapsedThreads) if err != nil { - return "", model.NewAppError("GetPostIdAfterTime", "app.post.get_post_id_around.app_error", nil, err.Error(), http.StatusInternalServerError) + return "", model.NewAppError("GetPostIdAfterTime", "app.post.get_post_id_around.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return postID, nil @@ -1099,7 +1099,7 @@ func (a *App) GetPostIdAfterTime(channelID string, time int64, collapsedThreads func (a *App) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError) { postID, err := a.Srv().Store.Post().GetPostIdBeforeTime(channelID, time, collapsedThreads) if err != nil { - return "", model.NewAppError("GetPostIdBeforeTime", "app.post.get_post_id_around.app_error", nil, err.Error(), http.StatusInternalServerError) + return "", model.NewAppError("GetPostIdBeforeTime", "app.post.get_post_id_around.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return postID, nil @@ -1226,7 +1226,7 @@ func (a *App) GetPostsForChannelAroundLastUnread(c request.CTX, channelID, userI func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post, *model.AppError) { post, err := a.Srv().Store.Post().GetSingle(postID, false) if err != nil { - return nil, model.NewAppError("DeletePost", "app.post.get.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("DeletePost", "app.post.get.app_error", nil, "", http.StatusBadRequest).Wrap(err) } channel, appErr := a.GetChannel(c, post.ChannelId) @@ -1244,7 +1244,7 @@ func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post, var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("DeletePost", "app.post.delete.app_error", nil, "", http.StatusNotFound).Wrap(nfErr) + return nil, model.NewAppError("DeletePost", "app.post.delete.app_error", nil, "", http.StatusNotFound).Wrap(err) default: return nil, model.NewAppError("DeletePost", "app.post.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } @@ -1565,9 +1565,9 @@ func (a *App) GetFileInfosForPostWithMigration(postID string, includeDeleted boo var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, model.NewAppError("GetFileInfosForPostWithMigration", "app.post.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetFileInfosForPostWithMigration", "app.post.get.app_error", nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, model.NewAppError("GetFileInfosForPostWithMigration", "app.post.get.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetFileInfosForPostWithMigration", "app.post.get.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } post := result.Data.(*model.Post) @@ -1586,7 +1586,7 @@ func (a *App) GetFileInfosForPostWithMigration(postID string, includeDeleted boo func (a *App) GetFileInfosForPost(postID string, fromMaster bool, includeDeleted bool) ([]*model.FileInfo, *model.AppError) { fileInfos, err := a.Srv().Store.FileInfo().GetForPost(postID, fromMaster, includeDeleted, true) if err != nil { - return nil, model.NewAppError("GetFileInfosForPost", "app.file_info.get_for_post.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetFileInfosForPost", "app.file_info.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.generateMiniPreviewForInfos(fileInfos) @@ -1665,7 +1665,7 @@ func (a *App) countThreadMentions(c request.CTX, user *model.User, post *model.P posts, nErr := a.Srv().Store.Thread().GetPosts(post.Id, timestamp) if nErr != nil { - return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } count := 0 @@ -1692,7 +1692,7 @@ func (a *App) countThreadMentions(c request.CTX, user *model.User, post *model.P groups, nErr := a.getGroupsAllowedForReferenceInChannel(channel, team) if nErr != nil { - return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } for _, p := range posts { @@ -1719,7 +1719,7 @@ func (a *App) countMentionsFromPost(c request.CTX, user *model.User, post *model // In a DM channel, every post made by the other user is a mention count, countRoot, nErr := a.Srv().Store.Channel().CountPostsAfter(post.ChannelId, post.CreateAt-1, channel.GetOtherUserIdForDM(user.Id)) if nErr != nil { - return 0, 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return 0, 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return count, countRoot, nil @@ -1888,9 +1888,9 @@ func (a *App) GetPostsByIds(postIDs []string) ([]*model.Post, int64, *model.AppE var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, 0, model.NewAppError("GetPostsByIds", "app.post.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, 0, model.NewAppError("GetPostsByIds", "app.post.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, 0, model.NewAppError("GetPostsByIds", "app.post.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("GetPostsByIds", "app.post.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1909,11 +1909,11 @@ func (a *App) GetTopThreadsForTeamSince(c request.CTX, teamID, userID string, op topThreads, err := a.Srv().Store.Thread().GetTopThreadsForTeamSince(teamID, userID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage) if err != nil { - return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.post.get_top_threads_for_team_since.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.post.get_top_threads_for_team_since.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } topThreadsWithEmbedAndImage, err := includeEmbedsAndImages(a, c, topThreads, userID) if err != nil { - return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.post.get_top_threads_for_team_since.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.post.get_top_threads_for_team_since.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topThreadsWithEmbedAndImage, nil } @@ -1925,11 +1925,11 @@ func (a *App) GetTopThreadsForUserSince(c request.CTX, teamID, userID string, op topThreads, err := a.Srv().Store.Thread().GetTopThreadsForUserSince(teamID, userID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage) if err != nil { - return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.post.get_top_threads_for_team_since.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.post.get_top_threads_for_team_since.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } topThreadsWithEmbedAndImage, err := includeEmbedsAndImages(a, c, topThreads, userID) if err != nil { - return nil, model.NewAppError("GetTopChannelsForUserSince", "app.post.get_top_threads_for_user_since.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTopChannelsForUserSince", "app.post.get_top_threads_for_user_since.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topThreadsWithEmbedAndImage, nil } @@ -1943,12 +1943,12 @@ func (a *App) SetPostReminder(postID, userID string, targetTime int64) *model.Ap } err := a.Srv().Store.Post().SetPostReminder(reminder) if err != nil { - return model.NewAppError("SetPostReminder", "app.post_reminder.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetPostReminder", "app.post_reminder.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } metadata, err := a.Srv().Store.Post().GetPostReminderMetadata(postID) if err != nil { - return model.NewAppError("SetPostReminder", "app.post_reminder.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetPostReminder", "app.post_reminder.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } parsed := time.Unix(targetTime, 0).UTC().Format(time.RFC822) diff --git a/app/post_helpers.go b/app/post_helpers.go index 4ae91bf60f..d57a25a2da 100644 --- a/app/post_helpers.go +++ b/app/post_helpers.go @@ -147,7 +147,7 @@ func (a *App) filterInaccessiblePosts(postList *model.PostList, options filterPo lastAccessiblePostTime, appErr := a.GetLastAccessiblePostTime() if appErr != nil { - return model.NewAppError("filterInaccessiblePosts", "app.last_accessible_post.app_error", nil, appErr.Error(), http.StatusInternalServerError) + return model.NewAppError("filterInaccessiblePosts", "app.last_accessible_post.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr) } if lastAccessiblePostTime == 0 { // No need to filter, all posts are accessible @@ -229,7 +229,7 @@ func (a *App) getFilteredAccessiblePosts(posts []*model.Post, options filterPost filteredPosts := []*model.Post{} lastAccessiblePostTime, appErr := a.GetLastAccessiblePostTime() if appErr != nil { - return filteredPosts, 0, model.NewAppError("getFilteredAccessiblePosts", "app.last_accessible_post.app_error", nil, appErr.Error(), http.StatusInternalServerError) + return filteredPosts, 0, model.NewAppError("getFilteredAccessiblePosts", "app.last_accessible_post.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr) } else if lastAccessiblePostTime == 0 { // No need to filter, all posts are accessible return posts, 0, nil diff --git a/app/preference.go b/app/preference.go index 4f470dd108..f86a40a615 100644 --- a/app/preference.go +++ b/app/preference.go @@ -14,7 +14,7 @@ import ( func (a *App) GetPreferencesForUser(userID string) (model.Preferences, *model.AppError) { preferences, err := a.Srv().Store.Preference().GetAll(userID) if err != nil { - return nil, model.NewAppError("GetPreferencesForUser", "app.preference.get_all.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPreferencesForUser", "app.preference.get_all.app_error", nil, "", http.StatusBadRequest).Wrap(err) } return preferences, nil } @@ -22,7 +22,7 @@ func (a *App) GetPreferencesForUser(userID string) (model.Preferences, *model.Ap func (a *App) GetPreferenceByCategoryForUser(userID string, category string) (model.Preferences, *model.AppError) { preferences, err := a.Srv().Store.Preference().GetCategory(userID, category) if err != nil { - return nil, model.NewAppError("GetPreferenceByCategoryForUser", "app.preference.get_category.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPreferenceByCategoryForUser", "app.preference.get_category.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if len(preferences) == 0 { err := model.NewAppError("GetPreferenceByCategoryForUser", "api.preference.preferences_category.get.app_error", nil, "", http.StatusNotFound) @@ -34,7 +34,7 @@ func (a *App) GetPreferenceByCategoryForUser(userID string, category string) (mo func (a *App) GetPreferenceByCategoryAndNameForUser(userID string, category string, preferenceName string) (*model.Preference, *model.AppError) { res, err := a.Srv().Store.Preference().Get(userID, category, preferenceName) if err != nil { - return nil, model.NewAppError("GetPreferenceByCategoryAndNameForUser", "app.preference.get.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPreferenceByCategoryAndNameForUser", "app.preference.get.app_error", nil, "", http.StatusBadRequest).Wrap(err) } return res, nil } diff --git a/app/product_notices.go b/app/product_notices.go index 810cfe006a..0b387897ac 100644 --- a/app/product_notices.go +++ b/app/product_notices.go @@ -246,7 +246,7 @@ func (a *App) GetProductNotices(c *request.Context, userID, teamID string, clien views, err := a.Srv().Store.ProductNotices().GetViews(userID) if err != nil { - return nil, model.NewAppError("GetProductNotices", "api.system.update_viewed_notices.failed", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetProductNotices", "api.system.update_viewed_notices.failed", nil, "", http.StatusBadRequest).Wrap(err) } sku := a.Srv().ClientLicense()["SkuShortName"] @@ -301,7 +301,7 @@ func (a *App) GetProductNotices(c *request.Context, userID, teamID string, clien searchEngineVersion, &a.ch.cachedNotices[noticeIndex]) if err != nil { - return nil, model.NewAppError("GetProductNotices", "api.system.update_notices.validating_failed", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetProductNotices", "api.system.update_notices.validating_failed", nil, "", http.StatusBadRequest).Wrap(err) } if result { selectedLocale := "en" @@ -320,7 +320,7 @@ func (a *App) GetProductNotices(c *request.Context, userID, teamID string, clien // UpdateViewedProductNotices is called from the frontend to mark a set of notices as 'viewed' by user func (a *App) UpdateViewedProductNotices(userID string, noticeIds []string) *model.AppError { if err := a.Srv().Store.ProductNotices().View(userID, noticeIds); err != nil { - return model.NewAppError("UpdateViewedProductNotices", "api.system.update_viewed_notices.failed", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("UpdateViewedProductNotices", "api.system.update_viewed_notices.failed", nil, "", http.StatusBadRequest).Wrap(err) } return nil } @@ -362,15 +362,15 @@ func (a *App) UpdateProductNotices() *model.AppError { data, err := utils.GetURLWithCache(url, ¬icesCache, skip) if err != nil { - return model.NewAppError("UpdateProductNotices", "api.system.update_notices.fetch_failed", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("UpdateProductNotices", "api.system.update_notices.fetch_failed", nil, "", http.StatusBadRequest).Wrap(err) } a.ch.cachedNotices, err = model.UnmarshalProductNotices(data) if err != nil { - return model.NewAppError("UpdateProductNotices", "api.system.update_notices.parse_failed", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("UpdateProductNotices", "api.system.update_notices.parse_failed", nil, "", http.StatusBadRequest).Wrap(err) } if err := a.Srv().Store.ProductNotices().ClearOldNotices(a.ch.cachedNotices); err != nil { - return model.NewAppError("UpdateProductNotices", "api.system.update_notices.clear_failed", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("UpdateProductNotices", "api.system.update_notices.clear_failed", nil, "", http.StatusBadRequest).Wrap(err) } return nil } diff --git a/app/reaction.go b/app/reaction.go index 7451677f2c..0154e61e55 100644 --- a/app/reaction.go +++ b/app/reaction.go @@ -36,7 +36,7 @@ func (a *App) SaveReactionForPost(c *request.Context, reaction *model.Reaction) case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -63,7 +63,7 @@ func (a *App) SaveReactionForPost(c *request.Context, reaction *model.Reaction) func (a *App) GetReactionsForPost(postID string) ([]*model.Reaction, *model.AppError) { reactions, err := a.Srv().Store.Reaction().GetForPost(postID, true) if err != nil { - return nil, model.NewAppError("GetReactionsForPost", "app.reaction.get_for_post.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetReactionsForPost", "app.reaction.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return reactions, nil } @@ -73,7 +73,7 @@ func (a *App) GetBulkReactionsForPosts(postIDs []string) (map[string][]*model.Re allReactions, err := a.Srv().Store.Reaction().BulkGetForPosts(postIDs) if err != nil { - return nil, model.NewAppError("GetBulkReactionsForPosts", "app.reaction.bulk_get_for_post_ids.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetBulkReactionsForPosts", "app.reaction.bulk_get_for_post_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, reaction := range allReactions { @@ -103,7 +103,7 @@ func (a *App) GetTopReactionsForTeamSince(teamID string, userID string, opts *mo topReactionList, err := a.Srv().Store.Reaction().GetTopForTeamSince(teamID, userID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage) if err != nil { - return nil, model.NewAppError("GetTopReactionsForTeamSince", "app.reaction.get_top_for_team_since.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTopReactionsForTeamSince", "app.reaction.get_top_for_team_since.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topReactionList, nil } @@ -115,7 +115,7 @@ func (a *App) GetTopReactionsForUserSince(userID string, teamID string, opts *mo topReactionList, err := a.Srv().Store.Reaction().GetTopForUserSince(userID, teamID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage) if err != nil { - return nil, model.NewAppError("GetTopReactionsForUserSince", "app.reaction.get_top_for_user_since.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTopReactionsForUserSince", "app.reaction.get_top_for_user_since.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topReactionList, nil } @@ -136,7 +136,7 @@ func (a *App) DeleteReactionForPost(c *request.Context, reaction *model.Reaction } if _, err := a.Srv().Store.Reaction().Delete(reaction); err != nil { - return model.NewAppError("DeleteReactionForPost", "app.reaction.delete_all_with_emoji_name.get_reactions.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteReactionForPost", "app.reaction.delete_all_with_emoji_name.get_reactions.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // The post is always modified since the UpdateAt always changes diff --git a/app/remote_cluster.go b/app/remote_cluster.go index 3c46166eeb..c80388b1b7 100644 --- a/app/remote_cluster.go +++ b/app/remote_cluster.go @@ -18,10 +18,10 @@ func (a *App) AddRemoteCluster(rc *model.RemoteCluster) (*model.RemoteCluster, * rc, err := a.Srv().Store.RemoteCluster().Save(rc) if err != nil { if sqlstore.IsUniqueConstraintError(errors.Cause(err), []string{sqlstore.RemoteClusterSiteURLUniqueIndex}) { - return nil, model.NewAppError("AddRemoteCluster", "api.remote_cluster.save_not_unique.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AddRemoteCluster", "api.remote_cluster.save_not_unique.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } - return nil, model.NewAppError("AddRemoteCluster", "api.remote_cluster.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AddRemoteCluster", "api.remote_cluster.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return rc, nil } @@ -30,10 +30,10 @@ func (a *App) UpdateRemoteCluster(rc *model.RemoteCluster) (*model.RemoteCluster rc, err := a.Srv().Store.RemoteCluster().Update(rc) if err != nil { if sqlstore.IsUniqueConstraintError(errors.Cause(err), []string{sqlstore.RemoteClusterSiteURLUniqueIndex}) { - return nil, model.NewAppError("UpdateRemoteCluster", "api.remote_cluster.update_not_unique.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateRemoteCluster", "api.remote_cluster.update_not_unique.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } - return nil, model.NewAppError("UpdateRemoteCluster", "api.remote_cluster.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateRemoteCluster", "api.remote_cluster.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return rc, nil } @@ -41,7 +41,7 @@ func (a *App) UpdateRemoteCluster(rc *model.RemoteCluster) (*model.RemoteCluster func (a *App) DeleteRemoteCluster(remoteClusterId string) (bool, *model.AppError) { deleted, err := a.Srv().Store.RemoteCluster().Delete(remoteClusterId) if err != nil { - return false, model.NewAppError("DeleteRemoteCluster", "api.remote_cluster.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return false, model.NewAppError("DeleteRemoteCluster", "api.remote_cluster.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return deleted, nil } @@ -49,7 +49,7 @@ func (a *App) DeleteRemoteCluster(remoteClusterId string) (bool, *model.AppError func (a *App) GetRemoteCluster(remoteClusterId string) (*model.RemoteCluster, *model.AppError) { rc, err := a.Srv().Store.RemoteCluster().Get(remoteClusterId) if err != nil { - return nil, model.NewAppError("GetRemoteCluster", "api.remote_cluster.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetRemoteCluster", "api.remote_cluster.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return rc, nil } @@ -57,7 +57,7 @@ func (a *App) GetRemoteCluster(remoteClusterId string) (*model.RemoteCluster, *m func (a *App) GetAllRemoteClusters(filter model.RemoteClusterQueryFilter) ([]*model.RemoteCluster, *model.AppError) { list, err := a.Srv().Store.RemoteCluster().GetAll(filter) if err != nil { - return nil, model.NewAppError("GetAllRemoteClusters", "api.remote_cluster.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAllRemoteClusters", "api.remote_cluster.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, nil } @@ -65,7 +65,7 @@ func (a *App) GetAllRemoteClusters(filter model.RemoteClusterQueryFilter) ([]*mo func (a *App) UpdateRemoteClusterTopics(remoteClusterId string, topics string) (*model.RemoteCluster, *model.AppError) { rc, err := a.Srv().Store.RemoteCluster().UpdateTopics(remoteClusterId, topics) if err != nil { - return nil, model.NewAppError("UpdateRemoteClusterTopics", "api.remote_cluster.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateRemoteClusterTopics", "api.remote_cluster.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return rc, nil } @@ -73,7 +73,7 @@ func (a *App) UpdateRemoteClusterTopics(remoteClusterId string, topics string) ( func (a *App) SetRemoteClusterLastPingAt(remoteClusterId string) *model.AppError { err := a.Srv().Store.RemoteCluster().SetLastPingAt(remoteClusterId) if err != nil { - return model.NewAppError("SetRemoteClusterLastPingAt", "api.remote_cluster.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetRemoteClusterLastPingAt", "api.remote_cluster.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } diff --git a/app/role.go b/app/role.go index d0b946acf7..535a1b605f 100644 --- a/app/role.go +++ b/app/role.go @@ -22,9 +22,9 @@ func (a *App) GetRole(id string) (*model.Role, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetRole", "app.role.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetRole", "app.role.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetRole", "app.role.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetRole", "app.role.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -39,7 +39,7 @@ func (a *App) GetRole(id string) (*model.Role, *model.AppError) { func (a *App) GetAllRoles() ([]*model.Role, *model.AppError) { roles, err := a.Srv().Store.Role().GetAll() if err != nil { - return nil, model.NewAppError("GetAllRoles", "app.role.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAllRoles", "app.role.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } appErr := a.Srv().mergeChannelHigherScopedPermissions(roles) @@ -56,9 +56,9 @@ func (s *Server) GetRoleByName(ctx context.Context, name string) (*model.Role, * var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("GetRoleByName", "app.role.get_by_name.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetRoleByName", "app.role.get_by_name.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("GetRoleByName", "app.role.get_by_name.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetRoleByName", "app.role.get_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -77,7 +77,7 @@ func (a *App) GetRoleByName(ctx context.Context, name string) (*model.Role, *mod func (a *App) GetRolesByNames(names []string) ([]*model.Role, *model.AppError) { roles, nErr := a.Srv().Store.Role().GetByNames(names) if nErr != nil { - return nil, model.NewAppError("GetRolesByNames", "app.role.get_by_names.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetRolesByNames", "app.role.get_by_names.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } err := a.mergeChannelHigherScopedPermissions(roles) @@ -105,7 +105,7 @@ func (s *Server) mergeChannelHigherScopedPermissions(roles []*model.Role) *model higherScopedPermissionsMap, err := s.Store.Role().ChannelHigherScopedPermissions(higherScopeNamesToQuery) if err != nil { - return model.NewAppError("mergeChannelHigherScopedPermissions", "app.role.get_by_names.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("mergeChannelHigherScopedPermissions", "app.role.get_by_names.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, role := range roles { @@ -158,9 +158,9 @@ func (a *App) CreateRole(role *model.Role) (*model.Role, *model.AppError) { var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("CreateRole", "app.role.save.invalid_role.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateRole", "app.role.save.invalid_role.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("CreateRole", "app.role.save.insert.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateRole", "app.role.save.insert.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -173,9 +173,9 @@ func (a *App) UpdateRole(role *model.Role) (*model.Role, *model.AppError) { var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("UpdateRole", "app.role.save.invalid_role.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpdateRole", "app.role.save.invalid_role.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("UpdateRole", "app.role.save.insert.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateRole", "app.role.save.insert.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -197,7 +197,7 @@ func (a *App) UpdateRole(role *model.Role) (*model.Role, *model.AppError) { roleRetrievalFunc = func() ([]*model.Role, *model.AppError) { roles, nErr := a.Srv().Store.Role().AllChannelSchemeRoles() if nErr != nil { - return nil, model.NewAppError("UpdateRole", "app.role.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateRole", "app.role.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return roles, nil @@ -206,7 +206,7 @@ func (a *App) UpdateRole(role *model.Role) (*model.Role, *model.AppError) { roleRetrievalFunc = func() ([]*model.Role, *model.AppError) { roles, nErr := a.Srv().Store.Role().ChannelRolesUnderTeamRole(savedRole.Name) if nErr != nil { - return nil, model.NewAppError("UpdateRole", "app.role.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateRole", "app.role.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return roles, nil diff --git a/app/saml.go b/app/saml.go index b0b83ba159..1d90d09030 100644 --- a/app/saml.go +++ b/app/saml.go @@ -38,18 +38,18 @@ func (a *App) GetSamlMetadata() (string, *model.AppError) { func (a *App) writeSamlFile(filename string, fileData *multipart.FileHeader) *model.AppError { file, err := fileData.Open() if err != nil { - return model.NewAppError("AddSamlCertificate", "api.admin.add_certificate.open.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("AddSamlCertificate", "api.admin.add_certificate.open.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } defer file.Close() data, err := io.ReadAll(file) if err != nil { - return model.NewAppError("AddSamlCertificate", "api.admin.add_certificate.saving.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("AddSamlCertificate", "api.admin.add_certificate.saving.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } err = a.Srv().platform.SetConfigFile(filename, data) if err != nil { - return model.NewAppError("AddSamlCertificate", "api.admin.add_certificate.saving.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("AddSamlCertificate", "api.admin.add_certificate.saving.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -108,7 +108,7 @@ func (a *App) AddSamlIdpCertificate(fileData *multipart.FileHeader) *model.AppEr func (a *App) removeSamlFile(filename string) *model.AppError { if err := a.Srv().platform.RemoveConfigFile(filename); err != nil { - return model.NewAppError("RemoveSamlFile", "api.admin.remove_certificate.delete.app_error", map[string]any{"Filename": filename}, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RemoveSamlFile", "api.admin.remove_certificate.delete.app_error", map[string]any{"Filename": filename}, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -204,7 +204,7 @@ func (a *App) GetSamlMetadataFromIdp(idpMetadataURL string) (*model.SamlMetadata func (a *App) FetchSamlMetadataFromIdp(url string) ([]byte, *model.AppError) { resp, err := a.HTTPService().MakeClient(false).Get(url) if err != nil { - return nil, model.NewAppError("FetchSamlMetadataFromIdp", "app.admin.saml.invalid_response_from_idp.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("FetchSamlMetadataFromIdp", "app.admin.saml.invalid_response_from_idp.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if resp.StatusCode != http.StatusOK { @@ -214,7 +214,7 @@ func (a *App) FetchSamlMetadataFromIdp(url string) ([]byte, *model.AppError) { bodyXML, err := io.ReadAll(resp.Body) if err != nil { - return nil, model.NewAppError("FetchSamlMetadataFromIdp", "app.admin.saml.failure_read_response_body_from_idp.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("FetchSamlMetadataFromIdp", "app.admin.saml.failure_read_response_body_from_idp.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bodyXML, nil @@ -224,7 +224,7 @@ func (a *App) BuildSamlMetadataObject(idpMetadata []byte) (*model.SamlMetadataRe entityDescriptor := model.EntityDescriptor{} err := xml.Unmarshal(idpMetadata, &entityDescriptor) if err != nil { - return nil, model.NewAppError("BuildSamlMetadataObject", "app.admin.saml.failure_decode_metadata_xml_from_idp.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("BuildSamlMetadataObject", "app.admin.saml.failure_decode_metadata_xml_from_idp.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } data := &model.SamlMetadataResponse{} @@ -259,7 +259,7 @@ func (a *App) SetSamlIdpCertificateFromMetadata(data []byte) *model.AppError { block, _ := pem.Decode([]byte(fixedCertTxt)) if _, e := x509.ParseCertificate(block.Bytes); e != nil { - return model.NewAppError("SetSamlIdpCertificateFromMetadata", "api.admin.saml.failure_parse_idp_certificate.app_error", nil, e.Error(), http.StatusInternalServerError) + return model.NewAppError("SetSamlIdpCertificateFromMetadata", "api.admin.saml.failure_parse_idp_certificate.app_error", nil, "", http.StatusInternalServerError).Wrap(e) } data = pem.EncodeToMemory(&pem.Block{ @@ -268,7 +268,7 @@ func (a *App) SetSamlIdpCertificateFromMetadata(data []byte) *model.AppError { }) if err := a.Srv().platform.SetConfigFile(SamlIdpCertificateName, data); err != nil { - return model.NewAppError("SetSamlIdpCertificateFromMetadata", "api.admin.saml.failure_save_idp_certificate_file.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetSamlIdpCertificateFromMetadata", "api.admin.saml.failure_save_idp_certificate_file.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } cfg := a.Config().Clone() @@ -290,7 +290,7 @@ func (a *App) ResetSamlAuthDataToEmail(includeDeleted bool, dryRun bool, userIDs } numAffected, err := a.Srv().Store.User().ResetAuthDataToEmailForUsers(model.UserAuthServiceSaml, userIDs, includeDeleted, dryRun) if err != nil { - appErr = model.NewAppError("ResetAuthDataToEmail", "api.admin.saml.failure_reset_authdata_to_email.app_error", nil, err.Error(), http.StatusInternalServerError) + appErr = model.NewAppError("ResetAuthDataToEmail", "api.admin.saml.failure_reset_authdata_to_email.app_error", nil, "", http.StatusInternalServerError).Wrap(err) return } return diff --git a/app/scheme.go b/app/scheme.go index 460e32f998..8a9b5b031f 100644 --- a/app/scheme.go +++ b/app/scheme.go @@ -21,9 +21,9 @@ func (a *App) GetScheme(id string) (*model.Scheme, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetScheme", "app.scheme.get.app_error", nil, err.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetScheme", "app.scheme.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetScheme", "app.scheme.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetScheme", "app.scheme.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return scheme, nil @@ -39,9 +39,9 @@ func (a *App) GetSchemeByName(name string) (*model.Scheme, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetSchemeByName", "app.scheme.get.app_error", nil, err.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetSchemeByName", "app.scheme.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetSchemeByName", "app.scheme.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetSchemeByName", "app.scheme.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return scheme, nil @@ -62,7 +62,7 @@ func (s *Server) GetSchemes(scope string, offset int, limit int) ([]*model.Schem scheme, err := s.Store.Scheme().GetAllPage(scope, offset, limit) if err != nil { - return nil, model.NewAppError("GetSchemes", "app.scheme.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetSchemes", "app.scheme.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return scheme, nil } @@ -99,9 +99,9 @@ func (a *App) CreateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("CreateScheme", "app.scheme.save.invalid_scheme.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateScheme", "app.scheme.save.invalid_scheme.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("CreateScheme", "app.scheme.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateScheme", "app.scheme.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return scheme, nil @@ -134,9 +134,9 @@ func (a *App) UpdateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("UpdateScheme", "app.scheme.save.invalid_scheme.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpdateScheme", "app.scheme.save.invalid_scheme.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("UpdateScheme", "app.scheme.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateScheme", "app.scheme.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return scheme, nil @@ -152,9 +152,9 @@ func (a *App) DeleteScheme(schemeId string) (*model.Scheme, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("DeleteScheme", "app.scheme.get.app_error", nil, err.Error(), http.StatusNotFound) + return nil, model.NewAppError("DeleteScheme", "app.scheme.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("DeleteScheme", "app.scheme.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("DeleteScheme", "app.scheme.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return scheme, nil @@ -175,7 +175,7 @@ func (a *App) GetTeamsForScheme(scheme *model.Scheme, offset int, limit int) ([] teams, err := a.Srv().Store.Team().GetTeamsByScheme(scheme.Id, offset, limit) if err != nil { - return nil, model.NewAppError("GetTeamsForScheme", "app.team.get_by_scheme.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamsForScheme", "app.team.get_by_scheme.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teams, nil } @@ -195,7 +195,7 @@ func (a *App) GetChannelsForScheme(scheme *model.Scheme, offset int, limit int) channelList, nErr := a.Srv().Store.Channel().GetChannelsByScheme(scheme.Id, offset, limit) if nErr != nil { - return nil, model.NewAppError("GetChannelsForScheme", "app.channel.get_by_scheme.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelsForScheme", "app.channel.get_by_scheme.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return channelList, nil @@ -207,7 +207,7 @@ func (s *Server) IsPhase2MigrationCompleted() *model.AppError { } if _, err := s.Store.System().GetByName(model.MigrationKeyAdvancedPermissionsPhase2); err != nil { - return model.NewAppError("App.IsPhase2MigrationCompleted", "app.schemes.is_phase_2_migration_completed.not_completed.app_error", nil, err.Error(), http.StatusNotImplemented) + return model.NewAppError("App.IsPhase2MigrationCompleted", "app.schemes.is_phase_2_migration_completed.not_completed.app_error", nil, "", http.StatusNotImplemented).Wrap(err) } s.phase2PermissionsMigrationComplete = true diff --git a/app/server.go b/app/server.go index 8f641e8c7c..f1477d0129 100644 --- a/app/server.go +++ b/app/server.go @@ -1614,7 +1614,7 @@ func (s *Server) sendLicenseUpForRenewalEmail(users map[string]*model.User, lice renewalLink, _, appErr := s.GenerateLicenseRenewalLink() if appErr != nil { - return model.NewAppError("s.sendLicenseUpForRenewalEmail", "api.server.license_up_for_renewal.error_generating_link", nil, appErr.Error(), http.StatusInternalServerError) + return model.NewAppError("s.sendLicenseUpForRenewalEmail", "api.server.license_up_for_renewal.error_generating_link", nil, "", http.StatusInternalServerError).Wrap(appErr) } // we want to at least have one email sent out to an admin @@ -1721,7 +1721,7 @@ func (s *Server) doLicenseExpirationCheck() { func (s *Server) SendRemoveExpiredLicenseEmail(email string, renewalLink, locale, siteURL string) *model.AppError { if err := s.EmailService.SendRemoveExpiredLicenseEmail(renewalLink, email, locale, siteURL); err != nil { - return model.NewAppError("SendRemoveExpiredLicenseEmail", "api.license.remove_expired_license.failed.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SendRemoveExpiredLicenseEmail", "api.license.remove_expired_license.failed.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -2035,11 +2035,11 @@ func (s *Server) GetDefaultProfileImage(user *model.User) ([]byte, *model.AppErr if err != nil { switch { case errors.Is(err, users.DefaultFontError): - return nil, model.NewAppError("GetDefaultProfileImage", "api.user.create_profile_image.default_font.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetDefaultProfileImage", "api.user.create_profile_image.default_font.app_error", nil, "", http.StatusInternalServerError).Wrap(err) case errors.Is(err, users.UserInitialsError): - return nil, model.NewAppError("GetDefaultProfileImage", "api.user.create_profile_image.initial.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetDefaultProfileImage", "api.user.create_profile_image.initial.app_error", nil, "", http.StatusInternalServerError).Wrap(err) default: - return nil, model.NewAppError("GetDefaultProfileImage", "api.user.create_profile_image.encode.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetDefaultProfileImage", "api.user.create_profile_image.encode.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -2049,7 +2049,7 @@ func (s *Server) GetDefaultProfileImage(user *model.User) ([]byte, *model.AppErr func (s *Server) ReadFile(path string) ([]byte, *model.AppError) { result, nErr := s.FileBackend().ReadFile(path) if nErr != nil { - return nil, model.NewAppError("ReadFile", "api.file.read_file.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ReadFile", "api.file.read_file.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return result, nil } @@ -2108,7 +2108,7 @@ func runPostReminderJob(a *App) { func (a *App) GetAppliedSchemaMigrations() ([]model.AppliedMigration, *model.AppError) { table, err := a.Srv().Store.GetAppliedMigrations() if err != nil { - return nil, model.NewAppError("GetDBSchemaTable", "api.file.read_file.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetDBSchemaTable", "api.file.read_file.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return table, nil } diff --git a/app/session.go b/app/session.go index c412edaa67..4e32670b75 100644 --- a/app/session.go +++ b/app/session.go @@ -23,9 +23,9 @@ func (a *App) CreateSession(session *model.Session) (*model.Session, *model.AppE var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("CreateSession", "app.session.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateSession", "app.session.save.existing.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("CreateSession", "app.session.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateSession", "app.session.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -126,7 +126,7 @@ func (a *App) GetSession(token string) (*model.Session, *model.AppError) { func (a *App) GetSessions(userID string) ([]*model.Session, *model.AppError) { sessions, err := a.ch.srv.userService.GetSessions(userID) if err != nil { - return nil, model.NewAppError("GetSessions", "app.session.get_sessions.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetSessions", "app.session.get_sessions.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return sessions, nil @@ -136,11 +136,11 @@ func (a *App) RevokeAllSessions(userID string) *model.AppError { if err := a.ch.srv.userService.RevokeAllSessions(userID); err != nil { switch { case errors.Is(err, users.GetSessionError): - return model.NewAppError("RevokeAllSessions", "app.session.get_sessions.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeAllSessions", "app.session.get_sessions.app_error", nil, "", http.StatusInternalServerError).Wrap(err) case errors.Is(err, users.DeleteSessionError): - return model.NewAppError("RevokeAllSessions", "app.session.remove.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeAllSessions", "app.session.remove.app_error", nil, "", http.StatusInternalServerError).Wrap(err) default: - return model.NewAppError("RevokeAllSessions", "app.session.remove.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeAllSessions", "app.session.remove.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -157,9 +157,9 @@ func (a *App) RevokeSessionsFromAllUsers() *model.AppError { if err := a.ch.srv.userService.RevokeSessionsFromAllUsers(); err != nil { switch { case errors.Is(err, users.DeleteAllAccessDataError): - return model.NewAppError("RevokeSessionsFromAllUsers", "app.oauth.remove_access_data.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeSessionsFromAllUsers", "app.oauth.remove_access_data.app_error", nil, "", http.StatusInternalServerError).Wrap(err) default: - return model.NewAppError("RevokeSessionsFromAllUsers", "app.session.remove_all_sessions_for_team.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeSessionsFromAllUsers", "app.session.remove_all_sessions_for_team.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -188,7 +188,7 @@ func (a *App) ClearSessionCacheForAllUsersSkipClusterSend() { func (a *App) RevokeSessionsForDeviceId(userID string, deviceID string, currentSessionId string) *model.AppError { if err := a.ch.srv.userService.RevokeSessionsForDeviceId(userID, deviceID, currentSessionId); err != nil { - return model.NewAppError("RevokeSessionsForDeviceId", "app.session.get_sessions.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeSessionsForDeviceId", "app.session.get_sessions.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -197,7 +197,7 @@ func (a *App) RevokeSessionsForDeviceId(userID string, deviceID string, currentS func (a *App) GetSessionById(sessionID string) (*model.Session, *model.AppError) { session, err := a.ch.srv.userService.GetSessionByID(sessionID) if err != nil { - return nil, model.NewAppError("GetSessionById", "app.session.get.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetSessionById", "app.session.get.app_error", nil, "", http.StatusBadRequest).Wrap(err) } return session, nil @@ -206,7 +206,7 @@ func (a *App) GetSessionById(sessionID string) (*model.Session, *model.AppError) func (a *App) RevokeSessionById(sessionID string) *model.AppError { session, err := a.GetSessionById(sessionID) if err != nil { - return model.NewAppError("RevokeSessionById", "app.session.get.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("RevokeSessionById", "app.session.get.app_error", nil, "", http.StatusBadRequest).Wrap(err) } return a.RevokeSession(session) @@ -216,9 +216,9 @@ func (a *App) RevokeSession(session *model.Session) *model.AppError { if err := a.ch.srv.userService.RevokeSession(session); err != nil { switch { case errors.Is(err, users.DeleteSessionError): - return model.NewAppError("RevokeSession", "app.session.remove.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeSession", "app.session.remove.app_error", nil, "", http.StatusInternalServerError).Wrap(err) default: - return model.NewAppError("RevokeSession", "app.session.remove.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeSession", "app.session.remove.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -228,7 +228,7 @@ func (a *App) RevokeSession(session *model.Session) *model.AppError { func (a *App) AttachDeviceId(sessionID string, deviceID string, expiresAt int64) *model.AppError { _, err := a.Srv().Store.Session().UpdateDeviceId(sessionID, deviceID, expiresAt) if err != nil { - return model.NewAppError("AttachDeviceId", "app.session.update_device_id.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("AttachDeviceId", "app.session.update_device_id.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -331,9 +331,9 @@ func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAc var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("CreateUserAccessToken", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("CreateUserAccessToken", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("CreateUserAccessToken", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateUserAccessToken", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -350,7 +350,7 @@ func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAc case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("CreateUserAccessToken", "app.user_access_token.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateUserAccessToken", "app.user_access_token.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -368,7 +368,7 @@ func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAc func (a *App) createSessionForUserAccessToken(tokenString string) (*model.Session, *model.AppError) { token, nErr := a.Srv().Store.UserAccessToken().GetByToken(tokenString) if nErr != nil { - return nil, model.NewAppError("createSessionForUserAccessToken", "app.user_access_token.invalid_or_missing", nil, nErr.Error(), http.StatusUnauthorized) + return nil, model.NewAppError("createSessionForUserAccessToken", "app.user_access_token.invalid_or_missing", nil, "", http.StatusUnauthorized).Wrap(nErr) } if !token.IsActive { @@ -380,9 +380,9 @@ func (a *App) createSessionForUserAccessToken(tokenString string) (*model.Sessio var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("createSessionForUserAccessToken", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("createSessionForUserAccessToken", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("createSessionForUserAccessToken", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createSessionForUserAccessToken", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -418,9 +418,9 @@ func (a *App) createSessionForUserAccessToken(tokenString string) (*model.Sessio var invErr *store.ErrInvalidInput switch { case errors.As(nErr, &invErr): - return nil, model.NewAppError("CreateSession", "app.session.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateSession", "app.session.save.existing.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) default: - return nil, model.NewAppError("CreateSession", "app.session.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateSession", "app.session.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -435,7 +435,7 @@ func (a *App) RevokeUserAccessToken(token *model.UserAccessToken) *model.AppErro session, _ = a.ch.srv.userService.GetSessionContext(context.Background(), token.Token) if err := a.Srv().Store.UserAccessToken().Delete(token.Id); err != nil { - return model.NewAppError("RevokeUserAccessToken", "app.user_access_token.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RevokeUserAccessToken", "app.user_access_token.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if session == nil { @@ -450,7 +450,7 @@ func (a *App) DisableUserAccessToken(token *model.UserAccessToken) *model.AppErr session, _ = a.ch.srv.userService.GetSessionContext(context.Background(), token.Token) if err := a.Srv().Store.UserAccessToken().UpdateTokenDisable(token.Id); err != nil { - return model.NewAppError("DisableUserAccessToken", "app.user_access_token.update_token_disable.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DisableUserAccessToken", "app.user_access_token.update_token_disable.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if session == nil { @@ -466,7 +466,7 @@ func (a *App) EnableUserAccessToken(token *model.UserAccessToken) *model.AppErro err := a.Srv().Store.UserAccessToken().UpdateTokenEnable(token.Id) if err != nil { - return model.NewAppError("EnableUserAccessToken", "app.user_access_token.update_token_enable.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("EnableUserAccessToken", "app.user_access_token.update_token_enable.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if session == nil { @@ -479,7 +479,7 @@ func (a *App) EnableUserAccessToken(token *model.UserAccessToken) *model.AppErro func (a *App) GetUserAccessTokens(page, perPage int) ([]*model.UserAccessToken, *model.AppError) { tokens, err := a.Srv().Store.UserAccessToken().GetAll(page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetUserAccessTokens", "app.user_access_token.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUserAccessTokens", "app.user_access_token.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, token := range tokens { @@ -492,7 +492,7 @@ func (a *App) GetUserAccessTokens(page, perPage int) ([]*model.UserAccessToken, func (a *App) GetUserAccessTokensForUser(userID string, page, perPage int) ([]*model.UserAccessToken, *model.AppError) { tokens, err := a.Srv().Store.UserAccessToken().GetByUser(userID, page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetUserAccessTokensForUser", "app.user_access_token.get_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUserAccessTokensForUser", "app.user_access_token.get_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, token := range tokens { token.Token = "" @@ -508,9 +508,9 @@ func (a *App) GetUserAccessToken(tokenID string, sanitize bool) (*model.UserAcce var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetUserAccessToken", "app.user_access_token.get_by_user.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetUserAccessToken", "app.user_access_token.get_by_user.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetUserAccessToken", "app.user_access_token.get_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUserAccessToken", "app.user_access_token.get_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -523,7 +523,7 @@ func (a *App) GetUserAccessToken(tokenID string, sanitize bool) (*model.UserAcce func (a *App) SearchUserAccessTokens(term string) ([]*model.UserAccessToken, *model.AppError) { tokens, err := a.Srv().Store.UserAccessToken().Search(term) if err != nil { - return nil, model.NewAppError("SearchUserAccessTokens", "app.user_access_token.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchUserAccessTokens", "app.user_access_token.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, token := range tokens { token.Token = "" diff --git a/app/shared_channel.go b/app/shared_channel.go index d993fafd54..9ce513be17 100644 --- a/app/shared_channel.go +++ b/app/shared_channel.go @@ -23,7 +23,7 @@ func (a *App) checkChannelNotShared(c request.CTX, channelId string) error { if _, err := a.GetSharedChannel(channelId); err == nil { var errNotFound *store.ErrNotFound if errors.As(err, &errNotFound) { - return errors.New("channel is already shared") + return fmt.Errorf("channel is already shared: %w", err) } return fmt.Errorf("cannot find channel: %w", err) } @@ -34,7 +34,7 @@ func (a *App) checkChannelIsShared(channelId string) error { if _, err := a.GetSharedChannel(channelId); err != nil { var errNotFound *store.ErrNotFound if errors.As(err, &errNotFound) { - return errors.New("channel is not shared") + return fmt.Errorf("channel is not shared: %w", err) } return fmt.Errorf("cannot find channel: %w", err) } @@ -46,7 +46,7 @@ func (a *App) CheckCanInviteToSharedChannel(channelId string) error { if err != nil { var errNotFound *store.ErrNotFound if errors.As(err, &errNotFound) { - return errors.New("channel is not shared") + return fmt.Errorf("channel is not shared: %w", err) } return fmt.Errorf("cannot find channel: %w", err) } @@ -77,7 +77,7 @@ func (a *App) HasSharedChannel(channelID string) (bool, error) { func (a *App) GetSharedChannels(page int, perPage int, opts model.SharedChannelFilterOpts) ([]*model.SharedChannel, *model.AppError) { channels, err := a.Srv().Store.SharedChannel().GetAll(page*perPage, perPage, opts) if err != nil { - return nil, model.NewAppError("GetSharedChannels", "app.channel.get_channels.not_found.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetSharedChannels", "app.channel.get_channels.not_found.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channels, nil } @@ -126,9 +126,9 @@ func (a *App) GetRemoteClusterForUser(remoteID string, userID string) (*model.Re var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetRemoteClusterForUser", "api.context.remote_id_invalid.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetRemoteClusterForUser", "api.context.remote_id_invalid.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetRemoteClusterForUser", "api.context.remote_id_invalid.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetRemoteClusterForUser", "api.context.remote_id_invalid.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return rc, nil diff --git a/app/slashcommands/auto_users.go b/app/slashcommands/auto_users.go index 6a63beb866..56f0855845 100644 --- a/app/slashcommands/auto_users.go +++ b/app/slashcommands/auto_users.go @@ -57,7 +57,7 @@ func CreateBasicUser(a *app.App, client *model.Client4) error { } _, err = a.Srv().Store.User().VerifyEmail(ruser.Id, ruser.Email) if err != nil { - return model.NewAppError("CreateBasicUser", "app.user.verify_email.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("CreateBasicUser", "app.user.verify_email.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if _, nErr := a.Srv().Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id, CreateAt: model.GetMillis()}, *a.Config().TeamSettings.MaxUsersPerTeam); nErr != nil { var appErr *model.AppError @@ -67,11 +67,11 @@ func CreateBasicUser(a *app.App, client *model.Client4) error { case errors.As(nErr, &appErr): // in case we haven't converted to plain error. return appErr case errors.As(nErr, &conflictErr): - return model.NewAppError("CreateBasicUser", "app.create_basic_user.save_member.conflict.app_error", nil, nErr.Error(), http.StatusBadRequest) + return model.NewAppError("CreateBasicUser", "app.create_basic_user.save_member.conflict.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &limitExceededErr): - return model.NewAppError("CreateBasicUser", "app.create_basic_user.save_member.max_accounts.app_error", nil, nErr.Error(), http.StatusBadRequest) + return model.NewAppError("CreateBasicUser", "app.create_basic_user.save_member.max_accounts.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) default: // last fallback in case it doesn't map to an existing app error. - return model.NewAppError("CreateBasicUser", "app.create_basic_user.save_member.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("CreateBasicUser", "app.create_basic_user.save_member.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } diff --git a/app/status.go b/app/status.go index 377261eeb9..6d420e2993 100644 --- a/app/status.go +++ b/app/status.go @@ -79,7 +79,7 @@ func (a *App) GetStatusesByIds(userIDs []string) (map[string]any, *model.AppErro if len(missingUserIds) > 0 { statuses, err := a.Srv().Store.Status().GetByIds(missingUserIds) if err != nil { - return nil, model.NewAppError("GetStatusesByIds", "app.status.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetStatusesByIds", "app.status.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, s := range statuses { @@ -99,7 +99,7 @@ func (a *App) GetStatusesByIds(userIDs []string) (map[string]any, *model.AppErro return statusMap, nil } -//GetUserStatusesByIds used by apiV4 +// GetUserStatusesByIds used by apiV4 func (a *App) GetUserStatusesByIds(userIDs []string) ([]*model.Status, *model.AppError) { if !*a.Config().ServiceSettings.EnableUserStatuses { return []*model.Status{}, nil @@ -127,7 +127,7 @@ func (a *App) GetUserStatusesByIds(userIDs []string) ([]*model.Status, *model.Ap if len(missingUserIds) > 0 { statuses, err := a.Srv().Store.Status().GetByIds(missingUserIds) if err != nil { - return nil, model.NewAppError("GetUserStatusesByIds", "app.status.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUserStatusesByIds", "app.status.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, s := range statuses { @@ -379,9 +379,9 @@ func (a *App) GetStatus(userID string) (*model.Status, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetStatus", "app.status.get.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetStatus", "app.status.get.missing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetStatus", "app.status.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetStatus", "app.status.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } diff --git a/app/syncables.go b/app/syncables.go index 8b0b4cdc43..ed8806f7cd 100644 --- a/app/syncables.go +++ b/app/syncables.go @@ -204,7 +204,7 @@ func (a *App) deleteGroupConstrainedChannelMemberships(c request.CTX, channelID func (a *App) SyncSyncableRoles(syncableID string, syncableType model.GroupSyncableType) *model.AppError { permittedAdmins, err := a.Srv().Store.Group().PermittedSyncableAdmins(syncableID, syncableType) if err != nil { - return model.NewAppError("SyncSyncableRoles", "app.select_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SyncSyncableRoles", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.Log().Info( @@ -217,13 +217,13 @@ func (a *App) SyncSyncableRoles(syncableID string, syncableType model.GroupSynca case model.GroupSyncableTypeTeam: nErr := a.Srv().Store.Team().UpdateMembersRole(syncableID, permittedAdmins) if nErr != nil { - return model.NewAppError("App.SyncSyncableRoles", "app.update_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("App.SyncSyncableRoles", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return nil case model.GroupSyncableTypeChannel: nErr := a.Srv().Store.Channel().UpdateMembersRole(syncableID, permittedAdmins) if nErr != nil { - return model.NewAppError("App.SyncSyncableRoles", "app.update_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("App.SyncSyncableRoles", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } return nil default: diff --git a/app/team.go b/app/team.go index 3eadbd5935..42ccd56c80 100644 --- a/app/team.go +++ b/app/team.go @@ -159,22 +159,22 @@ func (a *App) CreateTeam(c request.CTX, team *model.Team) (*model.Team, *model.A case errors.As(err, &invErr): switch { case invErr.Entity == "Channel" && invErr.Field == "DeleteAt": - return nil, model.NewAppError("CreateTeam", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("CreateTeam", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest).Wrap(err) case invErr.Entity == "Channel" && invErr.Field == "Type": - return nil, model.NewAppError("CreateTeam", "store.sql_channel.save.direct_channel.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("CreateTeam", "store.sql_channel.save.direct_channel.app_error", nil, "", http.StatusBadRequest).Wrap(err) case invErr.Entity == "Channel" && invErr.Field == "Id": - return nil, model.NewAppError("CreateTeam", "store.sql_channel.save_channel.existing.app_error", nil, "id="+invErr.Value.(string), http.StatusBadRequest) + return nil, model.NewAppError("CreateTeam", "store.sql_channel.save_channel.existing.app_error", nil, "id="+invErr.Value.(string), http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("CreateTeam", "app.team.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateTeam", "app.team.save.existing.app_error", nil, "", http.StatusBadRequest).Wrap(err) } case errors.As(err, &cErr): - return nil, model.NewAppError("CreateTeam", store.ChannelExistsError, nil, cErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateTeam", store.ChannelExistsError, nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, <Err): - return nil, model.NewAppError("CreateTeam", "store.sql_channel.save_channel.limit.app_error", nil, ltErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateTeam", "store.sql_channel.save_channel.limit.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("CreateTeam", "app.team.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateTeam", "app.team.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -219,15 +219,15 @@ func (a *App) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("UpdateTeam", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("UpdateTeam", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(err) case errors.As(err, &invErr): - return nil, model.NewAppError("UpdateTeam", "app.team.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpdateTeam", "app.team.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): return nil, appErr case errors.As(err, &domErr): - return nil, model.NewAppError("UpdateTeam", "api.team.update_restricted_domains.mismatch.app_error", map[string]any{"Domain": domErr.Domain}, "", http.StatusBadRequest) + return nil, model.NewAppError("UpdateTeam", "api.team.update_restricted_domains.mismatch.app_error", map[string]any{"Domain": domErr.Domain}, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("UpdateTeam", "app.team.update.updating.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateTeam", "app.team.update.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -266,15 +266,15 @@ func (a *App) RenameTeam(team *model.Team, newTeamName string, newDisplayName st var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("RenameTeam", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("RenameTeam", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(err) case errors.As(err, &invErr): - return nil, model.NewAppError("RenameTeam", "app.team.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("RenameTeam", "app.team.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): return nil, appErr case errors.As(err, &domErr): - return nil, model.NewAppError("RenameTeam", "api.team.update_restricted_domains.mismatch.app_error", map[string]any{"Domain": domErr.Domain}, "", http.StatusBadRequest) + return nil, model.NewAppError("RenameTeam", "api.team.update_restricted_domains.mismatch.app_error", map[string]any{"Domain": domErr.Domain}, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("RenameTeam", "app.team.update.updating.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("RenameTeam", "app.team.update.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -295,11 +295,11 @@ func (a *App) UpdateTeamScheme(team *model.Team) (*model.Team, *model.AppError) var appErr *model.AppError switch { case errors.As(nErr, &invErr): - return nil, model.NewAppError("UpdateTeamScheme", "app.team.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpdateTeamScheme", "app.team.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("UpdateTeamScheme", "app.team.update.updating.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateTeamScheme", "app.team.update.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -335,11 +335,11 @@ func (a *App) UpdateTeamPrivacy(teamID string, teamType string, allowOpenInvite var appErr *model.AppError switch { case errors.As(nErr, &invErr): - return model.NewAppError("UpdateTeamPrivacy", "app.team.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("UpdateTeamPrivacy", "app.team.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &appErr): return appErr default: - return model.NewAppError("UpdateTeamPrivacy", "app.team.update.updating.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdateTeamPrivacy", "app.team.update.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -359,15 +359,15 @@ func (a *App) PatchTeam(teamID string, patch *model.TeamPatch) (*model.Team, *mo var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("PatchTeam", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("PatchTeam", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(err) case errors.As(err, &invErr): - return nil, model.NewAppError("PatchTeam", "app.team.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("PatchTeam", "app.team.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): return nil, appErr case errors.As(err, &domErr): - return nil, model.NewAppError("PatchTeam", "api.team.update_restricted_domains.mismatch.app_error", map[string]any{"Domain": domErr.Domain}, "", http.StatusBadRequest) + return nil, model.NewAppError("PatchTeam", "api.team.update_restricted_domains.mismatch.app_error", map[string]any{"Domain": domErr.Domain}, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("PatchTeam", "app.team.update.updating.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("PatchTeam", "app.team.update.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -392,11 +392,11 @@ func (a *App) RegenerateTeamInviteId(teamID string) (*model.Team, *model.AppErro var appErr *model.AppError switch { case errors.As(nErr, &invErr): - return nil, model.NewAppError("RegenerateTeamInviteId", "app.team.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("RegenerateTeamInviteId", "app.team.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("RegenerateTeamInviteId", "app.team.update.updating.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("RegenerateTeamInviteId", "app.team.update.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -450,9 +450,9 @@ func (a *App) UpdateTeamMemberRoles(teamID string, userID string, newRoles strin var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("UpdateTeamMemberRoles", "app.team.get_member.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("UpdateTeamMemberRoles", "app.team.get_member.missing.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("UpdateTeamMemberRoles", "app.team.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateTeamMemberRoles", "app.team.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -515,7 +515,7 @@ func (a *App) UpdateTeamMemberRoles(teamID string, userID string, newRoles strin case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("UpdateTeamMemberRoles", "app.team.save_member.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateTeamMemberRoles", "app.team.save_member.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -554,7 +554,7 @@ func (a *App) UpdateTeamMemberSchemeRoles(teamID string, userID string, isScheme case errors.As(nErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("UpdateTeamMemberSchemeRoles", "app.team.save_member.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateTeamMemberSchemeRoles", "app.team.save_member.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -598,9 +598,9 @@ func (a *App) AddUserToTeam(c request.CTX, teamID string, userID string, userReq var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, nil, model.NewAppError("AddUserToTeam", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, model.NewAppError("AddUserToTeam", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, nil, model.NewAppError("AddUserToTeam", "app.team.get.finding.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("AddUserToTeam", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } team := result.Data.(*model.Team) @@ -610,9 +610,9 @@ func (a *App) AddUserToTeam(c request.CTX, teamID string, userID string, userReq var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, nil, model.NewAppError("AddUserToTeam", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, model.NewAppError("AddUserToTeam", MissingAccountError, nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, nil, model.NewAppError("AddUserToTeam", "app.user.get.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("AddUserToTeam", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } user := result.Data.(*model.User) @@ -631,9 +631,9 @@ func (a *App) AddUserToTeamByTeamId(c *request.Context, teamID string, user *mod var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return model.NewAppError("AddUserToTeamByTeamId", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("AddUserToTeamByTeamId", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return model.NewAppError("AddUserToTeamByTeamId", "app.team.get.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("AddUserToTeamByTeamId", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -646,7 +646,7 @@ func (a *App) AddUserToTeamByTeamId(c *request.Context, teamID string, user *mod func (a *App) AddUserToTeamByToken(c *request.Context, userID string, tokenID string) (*model.Team, *model.TeamMember, *model.AppError) { token, err := a.Srv().Store.Token().GetByToken(tokenID) if err != nil { - return nil, nil, model.NewAppError("AddUserToTeamByToken", "api.user.create_user.signup_link_invalid.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, nil, model.NewAppError("AddUserToTeamByToken", "api.user.create_user.signup_link_invalid.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if token.Type != TokenTypeTeamInvitation && token.Type != TokenTypeGuestInvitation { @@ -679,9 +679,9 @@ func (a *App) AddUserToTeamByToken(c *request.Context, userID string, tokenID st var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, nil, model.NewAppError("AddUserToTeamByToken", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, model.NewAppError("AddUserToTeamByToken", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, nil, model.NewAppError("AddUserToTeamByToken", "app.team.get.finding.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("AddUserToTeamByToken", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } team := result.Data.(*model.Team) @@ -695,9 +695,9 @@ func (a *App) AddUserToTeamByToken(c *request.Context, userID string, tokenID st var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, nil, model.NewAppError("AddUserToTeamByToken", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, model.NewAppError("AddUserToTeamByToken", MissingAccountError, nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, nil, model.NewAppError("AddUserToTeamByToken", "app.user.get.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("AddUserToTeamByToken", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } user := result.Data.(*model.User) @@ -717,7 +717,7 @@ func (a *App) AddUserToTeamByToken(c *request.Context, userID string, tokenID st if token.Type == TokenTypeGuestInvitation { channels, err := a.Srv().Store.Channel().GetChannelsByIds(strings.Split(tokenData["channels"], " "), false) if err != nil { - return nil, nil, model.NewAppError("AddUserToTeamByToken", "app.channel.get_channels_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("AddUserToTeamByToken", "app.channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, channel := range channels { @@ -755,9 +755,9 @@ func (a *App) AddUserToTeamByInviteId(c *request.Context, inviteId string, userI var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, nil, model.NewAppError("AddUserToTeamByInviteId", "app.team.get_by_invite_id.finding.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, model.NewAppError("AddUserToTeamByInviteId", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, nil, model.NewAppError("AddUserToTeamByInviteId", "app.team.get_by_invite_id.finding.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("AddUserToTeamByInviteId", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } team := result.Data.(*model.Team) @@ -767,9 +767,9 @@ func (a *App) AddUserToTeamByInviteId(c *request.Context, inviteId string, userI var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, nil, model.NewAppError("AddUserToTeamByInviteId", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, model.NewAppError("AddUserToTeamByInviteId", MissingAccountError, nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, nil, model.NewAppError("AddUserToTeamByInviteId", "app.user.get.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("AddUserToTeamByInviteId", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } user := result.Data.(*model.User) @@ -790,19 +790,19 @@ func (a *App) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User, var limitExceededErr *store.ErrLimitExceeded switch { case errors.Is(err, teams.AcceptedDomainError): - return nil, model.NewAppError("JoinUserToTeam", "api.team.join_user_to_team.allowed_domains.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("JoinUserToTeam", "api.team.join_user_to_team.allowed_domains.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.Is(err, teams.MemberCountError): - return nil, model.NewAppError("JoinUserToTeam", "app.team.get_active_member_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("JoinUserToTeam", "app.team.get_active_member_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) case errors.Is(err, teams.MaxMemberCountError): - return nil, model.NewAppError("JoinUserToTeam", "app.team.join_user_to_team.max_accounts.app_error", nil, "teamId="+team.Id, http.StatusBadRequest) + return nil, model.NewAppError("JoinUserToTeam", "app.team.join_user_to_team.max_accounts.app_error", nil, "teamId="+team.Id, http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): // in case we haven't converted to plain error. return nil, appErr case errors.As(err, &conflictErr): - return nil, model.NewAppError("JoinUserToTeam", "app.team.join_user_to_team.save_member.conflict.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("JoinUserToTeam", "app.team.join_user_to_team.save_member.conflict.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &limitExceededErr): - return nil, model.NewAppError("JoinUserToTeam", "app.team.join_user_to_team.save_member.max_accounts.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("JoinUserToTeam", "app.team.join_user_to_team.save_member.max_accounts.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: // last fallback in case it doesn't map to an existing app error. - return nil, model.NewAppError("JoinUserToTeam", "app.team.join_user_to_team.save_member.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("JoinUserToTeam", "app.team.join_user_to_team.save_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } if alreadyAdded { @@ -810,7 +810,7 @@ func (a *App) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User, } if _, err := a.Srv().Store.User().UpdateUpdateAt(user.Id); err != nil { - return nil, model.NewAppError("JoinUserToTeam", "app.user.update_update.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("JoinUserToTeam", "app.user.update_update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } opts := &store.SidebarCategorySearchOpts{ @@ -873,9 +873,9 @@ func (a *App) GetTeam(teamID string) (*model.Team, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetTeam", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetTeam", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetTeam", "app.team.get.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeam", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -888,9 +888,9 @@ func (a *App) GetTeams(teamIDs []string) ([]*model.Team, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetTeam", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetTeam", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetTeam", "app.team.get.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeam", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -903,9 +903,9 @@ func (a *App) GetTeamByName(name string) (*model.Team, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetTeamByName", "app.team.get_by_name.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetTeamByName", "app.team.get_by_name.missing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetTeamByName", "app.team.get_by_name.app_error", nil, err.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetTeamByName", "app.team.get_by_name.app_error", nil, "", http.StatusNotFound).Wrap(err) } } @@ -918,9 +918,9 @@ func (a *App) GetTeamByInviteId(inviteId string) (*model.Team, *model.AppError) var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetTeamByInviteId", "app.team.get_by_invite_id.finding.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetTeamByInviteId", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetTeamByInviteId", "app.team.get_by_invite_id.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamByInviteId", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -930,7 +930,7 @@ func (a *App) GetTeamByInviteId(inviteId string) (*model.Team, *model.AppError) func (a *App) GetAllTeams() ([]*model.Team, *model.AppError) { teams, err := a.Srv().Store.Team().GetAll() if err != nil { - return nil, model.NewAppError("GetAllTeams", "app.team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAllTeams", "app.team.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teams, nil @@ -939,7 +939,7 @@ func (a *App) GetAllTeams() ([]*model.Team, *model.AppError) { func (a *App) GetAllTeamsPage(offset int, limit int, opts *model.TeamSearch) ([]*model.Team, *model.AppError) { teams, err := a.Srv().Store.Team().GetAllPage(offset, limit, opts) if err != nil { - return nil, model.NewAppError("GetAllTeamsPage", "app.team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAllTeamsPage", "app.team.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teams, nil @@ -948,11 +948,11 @@ func (a *App) GetAllTeamsPage(offset int, limit int, opts *model.TeamSearch) ([] func (a *App) GetAllTeamsPageWithCount(offset int, limit int, opts *model.TeamSearch) (*model.TeamsWithCount, *model.AppError) { totalCount, err := a.Srv().Store.Team().AnalyticsTeamCount(opts) if err != nil { - return nil, model.NewAppError("GetAllTeamsPageWithCount", "app.team.analytics_team_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAllTeamsPageWithCount", "app.team.analytics_team_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } teams, err := a.Srv().Store.Team().GetAllPage(offset, limit, opts) if err != nil { - return nil, model.NewAppError("GetAllTeamsPageWithCount", "app.team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAllTeamsPageWithCount", "app.team.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &model.TeamsWithCount{Teams: teams, TotalCount: totalCount}, nil } @@ -960,7 +960,7 @@ func (a *App) GetAllTeamsPageWithCount(offset int, limit int, opts *model.TeamSe func (a *App) GetAllPrivateTeams() ([]*model.Team, *model.AppError) { teams, err := a.Srv().Store.Team().GetAllPrivateTeamListing() if err != nil { - return nil, model.NewAppError("GetAllPrivateTeams", "app.team.get_all_private_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAllPrivateTeams", "app.team.get_all_private_team_listing.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teams, nil @@ -969,7 +969,7 @@ func (a *App) GetAllPrivateTeams() ([]*model.Team, *model.AppError) { func (a *App) GetAllPublicTeams() ([]*model.Team, *model.AppError) { teams, err := a.Srv().Store.Team().GetAllTeamListing() if err != nil { - return nil, model.NewAppError("GetAllPublicTeams", "app.team.get_all_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetAllPublicTeams", "app.team.get_all_team_listing.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teams, nil @@ -980,14 +980,14 @@ func (a *App) SearchAllTeams(searchOpts *model.TeamSearch) ([]*model.Team, int64 if searchOpts.IsPaginated() { teams, count, err := a.Srv().Store.Team().SearchAllPaged(searchOpts) if err != nil { - return nil, 0, model.NewAppError("SearchAllTeams", "app.team.search_all_team.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("SearchAllTeams", "app.team.search_all_team.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teams, count, nil } results, err := a.Srv().Store.Team().SearchAll(searchOpts) if err != nil { - return nil, 0, model.NewAppError("SearchAllTeams", "app.team.search_all_team.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, model.NewAppError("SearchAllTeams", "app.team.search_all_team.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return results, int64(len(results)), nil } @@ -995,7 +995,7 @@ func (a *App) SearchAllTeams(searchOpts *model.TeamSearch) ([]*model.Team, int64 func (a *App) SearchPublicTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError) { teams, err := a.Srv().Store.Team().SearchOpen(searchOpts) if err != nil { - return nil, model.NewAppError("SearchPublicTeams", "app.team.search_open_team.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchPublicTeams", "app.team.search_open_team.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teams, nil @@ -1004,7 +1004,7 @@ func (a *App) SearchPublicTeams(searchOpts *model.TeamSearch) ([]*model.Team, *m func (a *App) SearchPrivateTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError) { teams, err := a.Srv().Store.Team().SearchPrivate(searchOpts) if err != nil { - return nil, model.NewAppError("SearchPrivateTeams", "app.team.search_private_team.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchPrivateTeams", "app.team.search_private_team.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teams, nil @@ -1013,7 +1013,7 @@ func (a *App) SearchPrivateTeams(searchOpts *model.TeamSearch) ([]*model.Team, * func (a *App) GetTeamsForUser(userID string) ([]*model.Team, *model.AppError) { teams, err := a.Srv().Store.Team().GetTeamsByUserId(userID) if err != nil { - return nil, model.NewAppError("GetTeamsForUser", "app.team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamsForUser", "app.team.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teams, nil @@ -1025,9 +1025,9 @@ func (a *App) GetTeamMember(teamID, userID string) (*model.TeamMember, *model.Ap var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetTeamMember", "app.team.get_member.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetTeamMember", "app.team.get_member.missing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetTeamMember", "app.team.get_member.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamMember", "app.team.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1037,7 +1037,7 @@ func (a *App) GetTeamMember(teamID, userID string) (*model.TeamMember, *model.Ap func (a *App) GetTeamMembersForUser(userID string, excludeTeamID string, includeDeleted bool) ([]*model.TeamMember, *model.AppError) { teamMembers, err := a.Srv().Store.Team().GetTeamsForUser(context.Background(), userID, excludeTeamID, includeDeleted) if err != nil { - return nil, model.NewAppError("GetTeamMembersForUser", "app.team.get_members.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamMembersForUser", "app.team.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teamMembers, nil @@ -1046,7 +1046,7 @@ func (a *App) GetTeamMembersForUser(userID string, excludeTeamID string, include func (a *App) GetTeamMembersForUserWithPagination(userID string, page, perPage int) ([]*model.TeamMember, *model.AppError) { teamMembers, err := a.Srv().Store.Team().GetTeamsForUserWithPagination(userID, page, perPage) if err != nil { - return nil, model.NewAppError("GetTeamMembersForUserWithPagination", "app.team.get_members.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamMembersForUserWithPagination", "app.team.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teamMembers, nil @@ -1055,7 +1055,7 @@ func (a *App) GetTeamMembersForUserWithPagination(userID string, page, perPage i func (a *App) GetTeamMembers(teamID string, offset int, limit int, teamMembersGetOptions *model.TeamMembersGetOptions) ([]*model.TeamMember, *model.AppError) { teamMembers, err := a.Srv().Store.Team().GetMembers(teamID, offset, limit, teamMembersGetOptions) if err != nil { - return nil, model.NewAppError("GetTeamMembers", "app.team.get_members.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamMembers", "app.team.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teamMembers, nil @@ -1064,7 +1064,7 @@ func (a *App) GetTeamMembers(teamID string, offset int, limit int, teamMembersGe func (a *App) GetTeamMembersByIds(teamID string, userIDs []string, restrictions *model.ViewUsersRestrictions) ([]*model.TeamMember, *model.AppError) { teamMembers, err := a.Srv().Store.Team().GetMembersByIds(teamID, userIDs, restrictions) if err != nil { - return nil, model.NewAppError("GetTeamMembersByIds", "app.team.get_members_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamMembersByIds", "app.team.get_members_by_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teamMembers, nil @@ -1073,7 +1073,7 @@ func (a *App) GetTeamMembersByIds(teamID string, userIDs []string, restrictions func (a *App) GetCommonTeamIDsForTwoUsers(userID, otherUserID string) ([]string, *model.AppError) { teamIDs, err := a.Srv().Store.Team().GetCommonTeamIDsForTwoUsers(userID, otherUserID) if err != nil { - return nil, model.NewAppError("GetCommonTeamIDsForUsers", "app.team.get_common_team_ids_for_users.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetCommonTeamIDsForUsers", "app.team.get_common_team_ids_for_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return teamIDs, nil } @@ -1148,7 +1148,7 @@ func (a *App) GetTeamUnread(teamID, userID string) (*model.TeamUnread, *model.Ap channelUnreads, err := a.Srv().Store.Team().GetChannelUnreadsForTeam(teamID, userID) if err != nil { - return nil, model.NewAppError("GetTeamUnread", "app.team.get_unread.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamUnread", "app.team.get_unread.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } var teamUnread = &model.TeamUnread{ @@ -1191,9 +1191,9 @@ func (a *App) RemoveUserFromTeam(c request.CTX, teamID string, userID string, re var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return model.NewAppError("RemoveUserFromTeam", "app.team.get_by_invite_id.finding.app_error", nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("RemoveUserFromTeam", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return model.NewAppError("RemoveUserFromTeam", "app.team.get_by_invite_id.finding.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return model.NewAppError("RemoveUserFromTeam", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } team := result.Data.(*model.Team) @@ -1203,9 +1203,9 @@ func (a *App) RemoveUserFromTeam(c request.CTX, teamID string, userID string, re var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return model.NewAppError("RemoveUserFromTeam", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("RemoveUserFromTeam", MissingAccountError, nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return model.NewAppError("RemoveUserFromTeam", "app.user.get.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return model.NewAppError("RemoveUserFromTeam", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } user := result.Data.(*model.User) @@ -1238,23 +1238,23 @@ func (a *App) postProcessTeamMemberLeave(c request.CTX, teamMember *model.TeamMe var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return model.NewAppError("postProcessTeamMemberLeave", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("postProcessTeamMemberLeave", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return model.NewAppError("postProcessTeamMemberLeave", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("postProcessTeamMemberLeave", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } if _, err := a.Srv().Store.User().UpdateUpdateAt(user.Id); err != nil { - return model.NewAppError("postProcessTeamMemberLeave", "app.user.update_update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postProcessTeamMemberLeave", "app.user.update_update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Channel().ClearSidebarOnTeamLeave(user.Id, teamMember.TeamId); err != nil { - return model.NewAppError("postProcessTeamMemberLeave", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postProcessTeamMemberLeave", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // delete the preferences that set the last channel used in the team and other team specific preferences if err := a.Srv().Store.Preference().DeleteCategory(user.Id, teamMember.TeamId); err != nil { - return model.NewAppError("postProcessTeamMemberLeave", "app.preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postProcessTeamMemberLeave", "app.preference.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.ClearSessionCacheForUser(user.Id) @@ -1267,7 +1267,7 @@ func (a *App) postProcessTeamMemberLeave(c request.CTX, teamMember *model.TeamMe func (a *App) LeaveTeam(c request.CTX, team *model.Team, user *model.User, requestorId string) *model.AppError { teamMember, err := a.GetTeamMember(team.Id, user.Id) if err != nil { - return model.NewAppError("LeaveTeam", "api.team.remove_user_from_team.missing.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("LeaveTeam", "api.team.remove_user_from_team.missing.app_error", nil, "", http.StatusBadRequest).Wrap(err) } var channelList model.ChannelList @@ -1280,7 +1280,7 @@ func (a *App) LeaveTeam(c request.CTX, team *model.Team, user *model.User, reque if errors.As(nErr, &nfErr) { channelList = model.ChannelList{} } else { - return model.NewAppError("LeaveTeam", "app.channel.get_channels.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("LeaveTeam", "app.channel.get_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -1288,7 +1288,7 @@ func (a *App) LeaveTeam(c request.CTX, team *model.Team, user *model.User, reque if !channel.IsGroupOrDirect() { a.invalidateCacheForChannelMembers(channel.Id) if nErr = a.Srv().Store.Channel().RemoveMember(channel.Id, user.Id); nErr != nil { - return model.NewAppError("LeaveTeam", "app.channel.remove_member.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("LeaveTeam", "app.channel.remove_member.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } } @@ -1299,9 +1299,9 @@ func (a *App) LeaveTeam(c request.CTX, team *model.Team, user *model.User, reque var nfErr *store.ErrNotFound switch { case errors.As(cErr, &nfErr): - return model.NewAppError("LeaveTeam", "app.channel.get_by_name.missing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("LeaveTeam", "app.channel.get_by_name.missing.app_error", nil, "", http.StatusNotFound).Wrap(cErr) default: - return model.NewAppError("LeaveTeam", "app.channel.get_by_name.existing.app_error", nil, cErr.Error(), http.StatusInternalServerError) + return model.NewAppError("LeaveTeam", "app.channel.get_by_name.existing.app_error", nil, "", http.StatusInternalServerError).Wrap(cErr) } } @@ -1317,7 +1317,7 @@ func (a *App) LeaveTeam(c request.CTX, team *model.Team, user *model.User, reque } if err := a.ch.srv.teamService.RemoveTeamMember(teamMember); err != nil { - return model.NewAppError("RemoveTeamMemberFromTeam", "app.team.save_member.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RemoveTeamMemberFromTeam", "app.team.save_member.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.postProcessTeamMemberLeave(c, teamMember, requestorId); err != nil { @@ -1339,7 +1339,7 @@ func (a *App) postLeaveTeamMessage(c request.CTX, user *model.User, channel *mod } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("postRemoveFromChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postRemoveFromChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -1357,7 +1357,7 @@ func (a *App) postRemoveFromTeamMessage(c request.CTX, user *model.User, channel } if _, err := a.CreatePost(c, post, channel, false, true); err != nil { - return model.NewAppError("postRemoveFromTeamMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("postRemoveFromTeamMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -1383,7 +1383,7 @@ func (a *App) prepareInviteNewUsersToTeam(teamID, senderId string, channelIds [] if len(channelIds) > 0 { channels, err = a.Srv().Store.Channel().GetChannelsByIds(channelIds, false) if err != nil { - return nil, nil, nil, model.NewAppError("prepareInviteNewUsersToTeam", "app.channel.get_channels_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, nil, model.NewAppError("prepareInviteNewUsersToTeam", "app.channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } result := <-tchan @@ -1391,9 +1391,9 @@ func (a *App) prepareInviteNewUsersToTeam(teamID, senderId string, channelIds [] var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, nil, nil, model.NewAppError("prepareInviteNewUsersToTeam", "app.team.get_by_invite_id.finding.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, nil, model.NewAppError("prepareInviteNewUsersToTeam", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, nil, nil, model.NewAppError("prepareInviteNewUsersToTeam", "app.team.get_by_invite_id.finding.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, nil, model.NewAppError("prepareInviteNewUsersToTeam", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } team := result.Data.(*model.Team) @@ -1403,9 +1403,9 @@ func (a *App) prepareInviteNewUsersToTeam(teamID, senderId string, channelIds [] var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, nil, nil, model.NewAppError("prepareInviteNewUsersToTeam", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, nil, model.NewAppError("prepareInviteNewUsersToTeam", MissingAccountError, nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, nil, nil, model.NewAppError("prepareInviteNewUsersToTeam", "app.user.get.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, nil, model.NewAppError("prepareInviteNewUsersToTeam", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } user := result.Data.(*model.User) @@ -1520,7 +1520,7 @@ func (a *App) prepareInviteGuestsToChannels(teamID string, guestsInvite *model.G result := <-cchan if result.NErr != nil { - return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "app.channel.get_channels_by_ids.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "app.channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } channels := result.Data.([]*model.Channel) @@ -1529,9 +1529,9 @@ func (a *App) prepareInviteGuestsToChannels(teamID string, guestsInvite *model.G var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", MissingAccountError, nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "app.user.get.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } user := result.Data.(*model.User) @@ -1541,9 +1541,9 @@ func (a *App) prepareInviteGuestsToChannels(teamID string, guestsInvite *model.G var nfErr *store.ErrNotFound switch { case errors.As(result.NErr, &nfErr): - return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "app.team.get_by_invite_id.finding.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusNotFound).Wrap(result.NErr) default: - return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "app.team.get_by_invite_id.finding.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } team := result.Data.(*model.Team) @@ -1711,7 +1711,7 @@ func (a *App) FindTeamByName(name string) bool { func (a *App) GetTeamsUnreadForUser(excludeTeamId string, userID string, includeCollapsedThreads bool) ([]*model.TeamUnread, *model.AppError) { data, err := a.Srv().Store.Team().GetChannelUnreadsForAllTeams(excludeTeamId, userID) if err != nil { - return nil, model.NewAppError("GetTeamsUnreadForUser", "app.team.get_unread.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamsUnreadForUser", "app.team.get_unread.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } members := []*model.TeamUnread{} @@ -1753,7 +1753,7 @@ func (a *App) GetTeamsUnreadForUser(excludeTeamId string, userID string, include if includeCollapsedThreads { teamUnreads, err := a.Srv().Store.Thread().GetTeamsUnreadForUser(userID, teamIDs) if err != nil { - return nil, model.NewAppError("GetTeamsUnreadForUser", "app.team.get_unread.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamsUnreadForUser", "app.team.get_unread.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for teamID, member := range membersMap { if _, ok := teamUnreads[teamID]; ok { @@ -1785,18 +1785,18 @@ func (a *App) PermanentDeleteTeam(c request.CTX, team *model.Team) *model.AppErr var appErr *model.AppError switch { case errors.As(err, &invErr): - return model.NewAppError("PermanentDeleteTeam", "app.team.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("PermanentDeleteTeam", "app.team.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): return appErr default: - return model.NewAppError("PermanentDeleteTeam", "app.team.update.updating.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteTeam", "app.team.update.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } if channels, err := a.Srv().Store.Channel().GetTeamChannels(team.Id); err != nil { var nfErr *store.ErrNotFound if !errors.As(err, &nfErr) { - return model.NewAppError("PermanentDeleteTeam", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteTeam", "app.channel.get_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } else { for _, ch := range channels { @@ -1805,15 +1805,15 @@ func (a *App) PermanentDeleteTeam(c request.CTX, team *model.Team) *model.AppErr } if err := a.Srv().Store.Team().RemoveAllMembersByTeam(team.Id); err != nil { - return model.NewAppError("PermanentDeleteTeam", "app.team.remove_member.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteTeam", "app.team.remove_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Command().PermanentDeleteByTeam(team.Id); err != nil { - return model.NewAppError("PermanentDeleteTeam", "app.team.permanentdeleteteam.internal_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteTeam", "app.team.permanentdeleteteam.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Team().PermanentDelete(team.Id); err != nil { - return model.NewAppError("PermanentDeleteTeam", "app.team.permanent_delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteTeam", "app.team.permanent_delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if appErr := a.sendTeamEvent(team, model.WebsocketEventDeleteTeam); appErr != nil { @@ -1836,11 +1836,11 @@ func (a *App) SoftDeleteTeam(teamID string) *model.AppError { var appErr *model.AppError switch { case errors.As(nErr, &invErr): - return model.NewAppError("SoftDeleteTeam", "app.team.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("SoftDeleteTeam", "app.team.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &appErr): return appErr default: - return model.NewAppError("SoftDeleteTeam", "app.team.update.updating.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("SoftDeleteTeam", "app.team.update.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -1864,11 +1864,11 @@ func (a *App) RestoreTeam(teamID string) *model.AppError { var appErr *model.AppError switch { case errors.As(nErr, &invErr): - return model.NewAppError("RestoreTeam", "app.team.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("RestoreTeam", "app.team.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &appErr): return appErr default: - return model.NewAppError("RestoreTeam", "app.team.update.updating.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("RestoreTeam", "app.team.update.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -1898,13 +1898,13 @@ func (a *App) GetTeamStats(teamID string, restrictions *model.ViewUsersRestricti result := <-tchan if result.NErr != nil { - return nil, model.NewAppError("GetTeamStats", "app.team.get_member_count.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamStats", "app.team.get_member_count.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } stats.TotalMemberCount = result.Data.(int64) result = <-achan if result.NErr != nil { - return nil, model.NewAppError("GetTeamStats", "app.team.get_active_member_count.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamStats", "app.team.get_active_member_count.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } stats.ActiveMemberCount = result.Data.(int64) @@ -1979,7 +1979,7 @@ func (a *App) GetTeamIcon(team *model.Team) ([]byte, *model.AppError) { path := "teams/" + team.Id + "/teamIcon.png" data, err := a.ReadFile(path) if err != nil { - return nil, model.NewAppError("GetTeamIcon", "api.team.get_team_icon.read_file.app_error", nil, err.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetTeamIcon", "api.team.get_team_icon.read_file.app_error", nil, "", http.StatusNotFound).Wrap(err) } return data, nil @@ -1988,7 +1988,7 @@ func (a *App) GetTeamIcon(team *model.Team) ([]byte, *model.AppError) { func (a *App) SetTeamIcon(teamID string, imageData *multipart.FileHeader) *model.AppError { file, err := imageData.Open() if err != nil { - return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.open.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.open.app_error", nil, "", http.StatusBadRequest).Wrap(err) } defer file.Close() return a.SetTeamIconFromMultiPartFile(teamID, file) @@ -1998,7 +1998,7 @@ func (a *App) SetTeamIconFromMultiPartFile(teamID string, file multipart.File) * team, getTeamErr := a.GetTeam(teamID) if getTeamErr != nil { - return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.get_team.app_error", nil, getTeamErr.Error(), http.StatusBadRequest) + return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.get_team.app_error", nil, "", http.StatusBadRequest).Wrap(getTeamErr) } if *a.Config().FileSettings.DriverName == "" { @@ -2007,7 +2007,7 @@ func (a *App) SetTeamIconFromMultiPartFile(teamID string, file multipart.File) * if limitErr := checkImageLimits(file, *a.Config().FileSettings.MaxImageResolution); limitErr != nil { return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.check_image_limits.app_error", - nil, limitErr.Error(), http.StatusBadRequest) + nil, "", http.StatusBadRequest).Wrap(limitErr) } return a.SetTeamIconFromFile(team, file) @@ -2017,7 +2017,7 @@ func (a *App) SetTeamIconFromFile(team *model.Team, file io.Reader) *model.AppEr // Decode image into Image object img, _, err := image.Decode(file) if err != nil { - return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.decode.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.decode.app_error", nil, "", http.StatusBadRequest).Wrap(err) } orientation, _ := imaging.GetImageOrientation(file) @@ -2030,19 +2030,19 @@ func (a *App) SetTeamIconFromFile(team *model.Team, file io.Reader) *model.AppEr buf := new(bytes.Buffer) err = a.ch.imgEncoder.EncodePNG(buf, img) if err != nil { - return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.encode.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.encode.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } path := "teams/" + team.Id + "/teamIcon.png" if _, err := a.WriteFile(buf, path); err != nil { - return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.write_file.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.write_file.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } curTime := model.GetMillis() if err := a.Srv().Store.Team().UpdateLastTeamIconUpdate(team.Id, curTime); err != nil { - return model.NewAppError("SetTeamIcon", "api.team.team_icon.update.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("SetTeamIcon", "api.team.team_icon.update.app_error", nil, "", http.StatusBadRequest).Wrap(err) } // manually set time to avoid possible cluster inconsistencies @@ -2058,11 +2058,11 @@ func (a *App) SetTeamIconFromFile(team *model.Team, file io.Reader) *model.AppEr func (a *App) RemoveTeamIcon(teamID string) *model.AppError { team, err := a.GetTeam(teamID) if err != nil { - return model.NewAppError("RemoveTeamIcon", "api.team.remove_team_icon.get_team.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("RemoveTeamIcon", "api.team.remove_team_icon.get_team.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if err := a.Srv().Store.Team().UpdateLastTeamIconUpdate(teamID, 0); err != nil { - return model.NewAppError("RemoveTeamIcon", "api.team.team_icon.update.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("RemoveTeamIcon", "api.team.team_icon.update.app_error", nil, "", http.StatusBadRequest).Wrap(err) } team.LastTeamIconUpdate = 0 @@ -2076,13 +2076,13 @@ func (a *App) RemoveTeamIcon(teamID string) *model.AppError { func (a *App) InvalidateAllEmailInvites() *model.AppError { if err := a.Srv().Store.Token().RemoveAllTokensByType(TokenTypeTeamInvitation); err != nil { - return model.NewAppError("InvalidateAllEmailInvites", "api.team.invalidate_all_email_invites.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("InvalidateAllEmailInvites", "api.team.invalidate_all_email_invites.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Token().RemoveAllTokensByType(TokenTypeGuestInvitation); err != nil { - return model.NewAppError("InvalidateAllEmailInvites", "api.team.invalidate_all_email_invites.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("InvalidateAllEmailInvites", "api.team.invalidate_all_email_invites.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.InvalidateAllResendInviteEmailJobs(); err != nil { - return model.NewAppError("InvalidateAllEmailInvites", "api.team.invalidate_all_email_invites.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("InvalidateAllEmailInvites", "api.team.invalidate_all_email_invites.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } diff --git a/app/terms_of_service.go b/app/terms_of_service.go index 98db3341ba..157dae592b 100644 --- a/app/terms_of_service.go +++ b/app/terms_of_service.go @@ -27,11 +27,11 @@ func (a *App) CreateTermsOfService(text, userID string) (*model.TermsOfService, var appErr *model.AppError switch { case errors.As(err, &invErr): - return nil, model.NewAppError("CreateTermsOfService", "app.terms_of_service.create.existing.app_error", nil, "id="+termsOfService.Id, http.StatusBadRequest) + return nil, model.NewAppError("CreateTermsOfService", "app.terms_of_service.create.existing.app_error", nil, "id="+termsOfService.Id, http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("CreateTermsOfService", "app.terms_of_service.create.app_error", nil, "terms_of_service_id="+termsOfService.Id+",err="+err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateTermsOfService", "app.terms_of_service.create.app_error", nil, "terms_of_service_id="+termsOfService.Id, http.StatusInternalServerError).Wrap(err) } } @@ -44,9 +44,9 @@ func (a *App) GetLatestTermsOfService() (*model.TermsOfService, *model.AppError) var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetLatestTermsOfService", "app.terms_of_service.get.no_rows.app_error", nil, "err="+err.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetLatestTermsOfService", "app.terms_of_service.get.no_rows.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetLatestTermsOfService", "app.terms_of_service.get.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetLatestTermsOfService", "app.terms_of_service.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return termsOfService, nil @@ -58,9 +58,9 @@ func (a *App) GetTermsOfService(id string) (*model.TermsOfService, *model.AppErr var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetTermsOfService", "app.terms_of_service.get.no_rows.app_error", nil, "", http.StatusNotFound) + return nil, model.NewAppError("GetTermsOfService", "app.terms_of_service.get.no_rows.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetTermsOfService", "app.terms_of_service.get.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTermsOfService", "app.terms_of_service.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return termsOfService, nil diff --git a/app/upload.go b/app/upload.go index 319f7e2e34..e2e8e2afc4 100644 --- a/app/upload.go +++ b/app/upload.go @@ -115,7 +115,7 @@ func (a *App) runPluginsHook(c *request.Context, info *model.FileInfo, file io.R info.Size = written if fileErr := a.MoveFile(tmpPath, info.Path); fileErr != nil { return model.NewAppError("runPluginsHook", "app.upload.run_plugins_hook.move_fail", - nil, fileErr.Error(), http.StatusInternalServerError) + nil, "", http.StatusInternalServerError).Wrap(fileErr) } } else { if fileErr := a.RemoveFile(tmpPath); fileErr != nil { @@ -158,7 +158,7 @@ func (a *App) CreateUploadSession(c request.CTX, us *model.UploadSession) (*mode us, storeErr := a.Srv().Store.UploadSession().Save(us) if storeErr != nil { - return nil, model.NewAppError("CreateUploadSession", "app.upload.create.save.app_error", nil, storeErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateUploadSession", "app.upload.create.save.app_error", nil, "", http.StatusInternalServerError).Wrap(storeErr) } return us, nil @@ -171,10 +171,10 @@ func (a *App) GetUploadSession(uploadId string) (*model.UploadSession, *model.Ap switch { case errors.As(err, &nfErr): return nil, model.NewAppError("GetUpload", "app.upload.get.app_error", - nil, nfErr.Error(), http.StatusNotFound) + nil, "", http.StatusNotFound).Wrap(err) default: return nil, model.NewAppError("GetUpload", "app.upload.get.app_error", - nil, err.Error(), http.StatusInternalServerError) + nil, "", http.StatusInternalServerError).Wrap(err) } } return us, nil @@ -184,7 +184,7 @@ func (a *App) GetUploadSessionsForUser(userID string) ([]*model.UploadSession, * uss, err := a.Srv().Store.UploadSession().GetForUser(userID) if err != nil { return nil, model.NewAppError("GetUploadsForUser", "app.upload.get_for_user.app_error", - nil, err.Error(), http.StatusInternalServerError) + nil, "", http.StatusInternalServerError).Wrap(err) } return uss, nil } @@ -253,7 +253,7 @@ func (a *App) UploadData(c *request.Context, us *model.UploadSession, rd io.Read if written > 0 { us.FileOffset += written if storeErr := a.Srv().Store.UploadSession().Update(us); storeErr != nil { - return nil, model.NewAppError("UploadData", "app.upload.upload_data.update.app_error", nil, storeErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UploadData", "app.upload.upload_data.update.app_error", nil, "", http.StatusInternalServerError).Wrap(storeErr) } } if err != nil { @@ -268,14 +268,14 @@ func (a *App) UploadData(c *request.Context, us *model.UploadSession, rd io.Read // upload is done, create FileInfo file, err := a.FileReader(uploadPath) if err != nil { - return nil, model.NewAppError("UploadData", "app.upload.upload_data.read_file.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UploadData", "app.upload.upload_data.read_file.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // generate file info info, genErr := a.genFileInfoFromReader(us.Filename, file, us.FileSize) file.Close() if genErr != nil { - return nil, model.NewAppError("UploadData", "app.upload.upload_data.gen_info.app_error", nil, genErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UploadData", "app.upload.upload_data.gen_info.app_error", nil, "", http.StatusInternalServerError).Wrap(genErr) } info.CreatorId = us.UserId @@ -309,7 +309,7 @@ func (a *App) UploadData(c *request.Context, us *model.UploadSession, rd io.Read if us.Type == model.UploadTypeImport { if err := a.MoveFile(uploadPath, us.Path); err != nil { - return nil, model.NewAppError("UploadData", "app.upload.upload_data.move_file.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UploadData", "app.upload.upload_data.move_file.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -320,7 +320,7 @@ func (a *App) UploadData(c *request.Context, us *model.UploadSession, rd io.Read case errors.As(storeErr, &appErr): return nil, appErr default: - return nil, model.NewAppError("uploadData", "app.upload.upload_data.save.app_error", nil, storeErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("uploadData", "app.upload.upload_data.save.app_error", nil, "", http.StatusInternalServerError).Wrap(storeErr) } } diff --git a/app/usage.go b/app/usage.go index 0abe3ab03e..02a577712b 100644 --- a/app/usage.go +++ b/app/usage.go @@ -46,7 +46,7 @@ func (ch *Channels) getIntegrationsUsage() (*model.IntegrationsUsage, *model.App func (a *App) GetPostsUsage() (int64, *model.AppError) { count, err := a.Srv().Store.Post().AnalyticsPostCount(&model.PostCountOptions{ExcludeDeleted: true, UsersPostsOnly: true, AllowFromCache: true}) if err != nil { - return 0, model.NewAppError("GetPostsUsage", "app.post.analytics_posts_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("GetPostsUsage", "app.post.analytics_posts_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return utils.RoundOffToZeroesResolution(float64(count), 3), nil @@ -56,7 +56,7 @@ func (a *App) GetPostsUsage() (int64, *model.AppError) { func (a *App) GetStorageUsage() (int64, *model.AppError) { usage, err := a.Srv().Store.FileInfo().GetStorageUsage(true, false) if err != nil { - return 0, model.NewAppError("GetStorageUsage", "app.usage.get_storage_usage.app_error", nil, err.Error(), http.StatusInternalServerError) + return 0, model.NewAppError("GetStorageUsage", "app.usage.get_storage_usage.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return usage, nil } @@ -66,7 +66,7 @@ func (a *App) GetTeamsUsage() (*model.TeamsUsage, *model.AppError) { includeDeleted := false teamCount, err := a.Srv().Store.Team().AnalyticsTeamCount(&model.TeamSearch{IncludeDeleted: &includeDeleted}) if err != nil { - return nil, model.NewAppError("GetTeamsUsage", "app.post.analytics_teams_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamsUsage", "app.post.analytics_teams_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } usage.Active = teamCount diff --git a/app/user.go b/app/user.go index ec4d24063d..37caba1891 100644 --- a/app/user.go +++ b/app/user.go @@ -64,15 +64,15 @@ func (a *App) CreateUserWithToken(c request.CTX, user *model.User, token *model. var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("CreateUserWithToken", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("CreateUserWithToken", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("CreateUserWithToken", "app.team.get.finding.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateUserWithToken", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } channels, nErr := a.Srv().Store.Channel().GetChannelsByIds(strings.Split(tokenData["channels"], " "), false) if nErr != nil { - return nil, model.NewAppError("CreateUserWithToken", "app.channel.get_channels_by_ids.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateUserWithToken", "app.channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } emailFromToken := tokenData["email"] @@ -126,9 +126,9 @@ func (a *App) CreateUserWithInviteId(c request.CTX, user *model.User, inviteId, var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("CreateUserWithInviteId", "app.team.get_by_invite_id.finding.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("CreateUserWithInviteId", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("CreateUserWithInviteId", "app.team.get_by_invite_id.finding.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateUserWithInviteId", "app.team.get_by_invite_id.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -236,22 +236,22 @@ func (a *App) createUserOrGuest(c request.CTX, user *model.User, guest bool) (*m case errors.As(nErr, &appErr): return nil, appErr case errors.Is(nErr, users.AcceptedDomainError): - return nil, model.NewAppError("createUserOrGuest", "api.user.create_user.accepted_domain.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("createUserOrGuest", "api.user.create_user.accepted_domain.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &nfErr): - return nil, model.NewAppError("createUserOrGuest", "api.user.check_user_password.invalid.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("createUserOrGuest", "api.user.check_user_password.invalid.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.Is(nErr, users.UserStoreIsEmptyError): - return nil, model.NewAppError("createUserOrGuest", "app.user.store_is_empty.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createUserOrGuest", "app.user.store_is_empty.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) case errors.As(nErr, &invErr): switch invErr.Field { case "email": - return nil, model.NewAppError("createUserOrGuest", "app.user.save.email_exists.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("createUserOrGuest", "app.user.save.email_exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case "username": - return nil, model.NewAppError("createUserOrGuest", "app.user.save.username_exists.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("createUserOrGuest", "app.user.save.username_exists.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) default: - return nil, model.NewAppError("createUserOrGuest", "app.user.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("createUserOrGuest", "app.user.save.existing.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) } default: - return nil, model.NewAppError("createUserOrGuest", "app.user.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createUserOrGuest", "app.user.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -263,9 +263,9 @@ func (a *App) createUserOrGuest(c request.CTX, user *model.User, guest bool) (*m var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("createUserOrGuest", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("createUserOrGuest", MissingAccountError, nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("createUserOrGuest", "app.user.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("createUserOrGuest", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -319,7 +319,7 @@ func (a *App) CreateOAuthUser(c *request.Context, service string, userData io.Re } user, err1 := provider.GetUserFromJSON(userData, tokenUser) if err1 != nil { - return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.create.app_error", map[string]any{"Service": service}, err1.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.create.app_error", map[string]any{"Service": service}, "", http.StatusInternalServerError).Wrap(err1) } if user.AuthService == "" { user.AuthService = service @@ -382,9 +382,9 @@ func (a *App) GetUser(userID string) (*model.User, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetUser", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetUser", MissingAccountError, nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetUser", "app.user.get_by_username.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUser", "app.user.get_by_username.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -394,7 +394,7 @@ func (a *App) GetUser(userID string) (*model.User, *model.AppError) { func (a *App) GetUsers(userIDs []string) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsers(userIDs) if err != nil { - return nil, model.NewAppError("GetUsers", "app.user.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsers", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -406,9 +406,9 @@ func (a *App) GetUserByUsername(username string) (*model.User, *model.AppError) var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetUserByUsername", "app.user.get_by_username.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetUserByUsername", "app.user.get_by_username.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetUserByUsername", "app.user.get_by_username.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUserByUsername", "app.user.get_by_username.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } return result, nil @@ -420,9 +420,9 @@ func (a *App) GetUserByEmail(email string) (*model.User, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetUserByEmail", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetUserByEmail", MissingAccountError, nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetUserByEmail", MissingAccountError, nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUserByEmail", MissingAccountError, nil, "", http.StatusInternalServerError).Wrap(err) } } return user, nil @@ -435,11 +435,11 @@ func (a *App) GetUserByAuth(authData *string, authService string) (*model.User, var nfErr *store.ErrNotFound switch { case errors.As(err, &invErr): - return nil, model.NewAppError("GetUserByAuth", MissingAuthAccountError, nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetUserByAuth", MissingAuthAccountError, nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &nfErr): - return nil, model.NewAppError("GetUserByAuth", MissingAuthAccountError, nil, nfErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUserByAuth", MissingAuthAccountError, nil, "", http.StatusInternalServerError).Wrap(err) default: - return nil, model.NewAppError("GetUserByAuth", "app.user.get_by_auth.other.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUserByAuth", "app.user.get_by_auth.other.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -449,7 +449,7 @@ func (a *App) GetUserByAuth(authData *string, authService string) (*model.User, func (a *App) GetUsersFromProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsersFromProfiles(options) if err != nil { - return nil, model.NewAppError("GetUsers", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsers", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -458,7 +458,7 @@ func (a *App) GetUsersFromProfiles(options *model.UserGetOptions) ([]*model.User func (a *App) GetUsersPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsersPage(options, asAdmin) if err != nil { - return nil, model.NewAppError("GetUsersPage", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersPage", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -471,7 +471,7 @@ func (a *App) GetUsersEtag(restrictionsHash string) string { func (a *App) GetUsersInTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsersInTeam(options) if err != nil { - return nil, model.NewAppError("GetUsersInTeam", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersInTeam", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -480,7 +480,7 @@ func (a *App) GetUsersInTeam(options *model.UserGetOptions) ([]*model.User, *mod func (a *App) GetUsersNotInTeam(teamID string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsersNotInTeam(teamID, groupConstrained, offset, limit, viewRestrictions) if err != nil { - return nil, model.NewAppError("GetUsersNotInTeam", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersNotInTeam", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -489,7 +489,7 @@ func (a *App) GetUsersNotInTeam(teamID string, groupConstrained bool, offset int func (a *App) GetUsersInTeamPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsersInTeamPage(options, asAdmin) if err != nil { - return nil, model.NewAppError("GetUsersInTeamPage", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersInTeamPage", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return a.sanitizeProfiles(users, asAdmin), nil @@ -498,7 +498,7 @@ func (a *App) GetUsersInTeamPage(options *model.UserGetOptions, asAdmin bool) ([ func (a *App) GetUsersNotInTeamPage(teamID string, groupConstrained bool, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsersNotInTeamPage(teamID, groupConstrained, page*perPage, perPage, asAdmin, viewRestrictions) if err != nil { - return nil, model.NewAppError("GetUsersNotInTeamPage", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersNotInTeamPage", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return a.sanitizeProfiles(users, asAdmin), nil @@ -515,7 +515,7 @@ func (a *App) GetUsersNotInTeamEtag(teamID string, restrictionsHash string) stri func (a *App) GetUsersInChannel(options *model.UserGetOptions) ([]*model.User, *model.AppError) { users, err := a.Srv().Store.User().GetProfilesInChannel(options) if err != nil { - return nil, model.NewAppError("GetUsersInChannel", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersInChannel", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -524,7 +524,7 @@ func (a *App) GetUsersInChannel(options *model.UserGetOptions) ([]*model.User, * func (a *App) GetUsersInChannelByStatus(options *model.UserGetOptions) ([]*model.User, *model.AppError) { users, err := a.Srv().Store.User().GetProfilesInChannelByStatus(options) if err != nil { - return nil, model.NewAppError("GetUsersInChannelByStatus", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersInChannelByStatus", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -533,7 +533,7 @@ func (a *App) GetUsersInChannelByStatus(options *model.UserGetOptions) ([]*model func (a *App) GetUsersInChannelByAdmin(options *model.UserGetOptions) ([]*model.User, *model.AppError) { users, err := a.Srv().Store.User().GetProfilesInChannelByAdmin(options) if err != nil { - return nil, model.NewAppError("GetUsersInChannelByAdmin", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersInChannelByAdmin", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -582,7 +582,7 @@ func (a *App) GetUsersInChannelPageByAdmin(options *model.UserGetOptions, asAdmi func (a *App) GetUsersNotInChannel(teamID string, channelID string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { users, err := a.Srv().Store.User().GetProfilesNotInChannel(teamID, channelID, groupConstrained, offset, limit, viewRestrictions) if err != nil { - return nil, model.NewAppError("GetUsersNotInChannel", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersNotInChannel", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -616,7 +616,7 @@ func (a *App) GetUsersNotInChannelPage(teamID string, channelID string, groupCon func (a *App) GetUsersWithoutTeamPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsersWithoutTeamPage(options, asAdmin) if err != nil { - return nil, model.NewAppError("GetUsersWithoutTeamPage", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersWithoutTeamPage", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return a.sanitizeProfiles(users, asAdmin), nil @@ -625,7 +625,7 @@ func (a *App) GetUsersWithoutTeamPage(options *model.UserGetOptions, asAdmin boo func (a *App) GetUsersWithoutTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsersWithoutTeam(options) if err != nil { - return nil, model.NewAppError("GetUsersWithoutTeam", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersWithoutTeam", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -635,7 +635,7 @@ func (a *App) GetUsersWithoutTeam(options *model.UserGetOptions) ([]*model.User, func (a *App) GetTeamGroupUsers(teamID string) ([]*model.User, *model.AppError) { users, err := a.Srv().Store.User().GetTeamGroupUsers(teamID) if err != nil { - return nil, model.NewAppError("GetTeamGroupUsers", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTeamGroupUsers", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -645,7 +645,7 @@ func (a *App) GetTeamGroupUsers(teamID string) ([]*model.User, *model.AppError) func (a *App) GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError) { users, err := a.Srv().Store.User().GetChannelGroupUsers(channelID) if err != nil { - return nil, model.NewAppError("GetChannelGroupUsers", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetChannelGroupUsers", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -654,7 +654,7 @@ func (a *App) GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppE func (a *App) GetUsersByIds(userIDs []string, options *store.UserGetByIdsOpts) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsersByIds(userIDs, options) if err != nil { - return nil, model.NewAppError("GetUsersByIds", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersByIds", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -663,7 +663,7 @@ func (a *App) GetUsersByIds(userIDs []string, options *store.UserGetByIdsOpts) ( func (a *App) GetUsersByGroupChannelIds(c *request.Context, channelIDs []string, asAdmin bool) (map[string][]*model.User, *model.AppError) { usersByChannelId, err := a.Srv().Store.User().GetProfileByGroupChannelIdsForUser(c.Session().UserId, channelIDs) if err != nil { - return nil, model.NewAppError("GetUsersByGroupChannelIds", "app.user.get_profile_by_group_channel_ids_for_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersByGroupChannelIds", "app.user.get_profile_by_group_channel_ids_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for channelID, userList := range usersByChannelId { usersByChannelId[channelID] = a.sanitizeProfiles(userList, asAdmin) @@ -675,7 +675,7 @@ func (a *App) GetUsersByGroupChannelIds(c *request.Context, channelIDs []string, func (a *App) GetUsersByUsernames(usernames []string, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) { users, err := a.ch.srv.userService.GetUsersByUsernames(usernames, &model.UserGetOptions{ViewRestrictions: viewRestrictions}) if err != nil { - return nil, model.NewAppError("GetUsersByUsernames", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersByUsernames", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return a.sanitizeProfiles(users, asAdmin), nil } @@ -700,7 +700,7 @@ func (a *App) GenerateMfaSecret(userID string) (*model.MfaSecret, *model.AppErro mfaSecret, err := a.ch.srv.userService.GenerateMfaSecret(user) if err != nil { - return nil, model.NewAppError("GenerateMfaSecret", "mfa.generate_qr_code.create_code.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GenerateMfaSecret", "mfa.generate_qr_code.create_code.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return mfaSecret, nil @@ -725,7 +725,7 @@ func (a *App) ActivateMfa(userID, token string) *model.AppError { case errors.Is(err, mfa.InvalidToken): return model.NewAppError("ActivateMfa", "mfa.activate.bad_token.app_error", nil, "", http.StatusUnauthorized) default: - return model.NewAppError("ActivateMfa", "mfa.activate.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ActivateMfa", "mfa.activate.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -742,7 +742,7 @@ func (a *App) DeactivateMfa(userID string) *model.AppError { } if err := a.ch.srv.userService.DeactivateMfa(user); err != nil { - return model.NewAppError("DeactivateMfa", "mfa.deactivate.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeactivateMfa", "mfa.deactivate.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Make sure old MFA status is not cached locally or in cluster nodes. @@ -795,7 +795,7 @@ func (a *App) SetDefaultProfileImage(c request.CTX, user *model.User) *model.App func (a *App) SetProfileImage(c request.CTX, userID string, imageData *multipart.FileHeader) *model.AppError { file, err := imageData.Open() if err != nil { - return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.open.app_error", nil, err.Error(), http.StatusBadRequest) + return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.open.app_error", nil, "", http.StatusBadRequest).Wrap(err) } defer file.Close() return a.SetProfileImageFromMultiPartFile(c, userID, file) @@ -813,7 +813,7 @@ func (a *App) AdjustImage(file io.Reader) (*bytes.Buffer, *model.AppError) { // Decode image into Image object img, _, err := a.ch.imgDecoder.Decode(file) if err != nil { - return nil, model.NewAppError("SetProfileImage", "api.user.upload_profile_user.decode.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("SetProfileImage", "api.user.upload_profile_user.decode.app_error", nil, "", http.StatusBadRequest).Wrap(err) } orientation, _ := imaging.GetImageOrientation(file) @@ -826,7 +826,7 @@ func (a *App) AdjustImage(file io.Reader) (*bytes.Buffer, *model.AppError) { buf := new(bytes.Buffer) err = a.ch.imgEncoder.EncodePNG(buf, img) if err != nil { - return nil, model.NewAppError("SetProfileImage", "api.user.upload_profile_user.encode.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SetProfileImage", "api.user.upload_profile_user.encode.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return buf, nil } @@ -843,7 +843,7 @@ func (a *App) SetProfileImageFromFile(c request.CTX, userID string, file io.Read } if _, err := a.WriteFile(buf, path); err != nil { - return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.upload_profile.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.upload_profile.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.User().UpdateLastPictureUpdate(userID); err != nil { @@ -862,13 +862,11 @@ func (a *App) UpdatePasswordAsUser(c request.CTX, userID, currentPassword, newPa } if user == nil { - err = model.NewAppError("updatePassword", "api.user.update_password.valid_account.app_error", nil, "", http.StatusBadRequest) - return err + return model.NewAppError("updatePassword", "api.user.update_password.valid_account.app_error", nil, "", http.StatusBadRequest) } if user.AuthData != nil && *user.AuthData != "" { - err = model.NewAppError("updatePassword", "api.user.update_password.oauth.app_error", nil, "auth_service="+user.AuthService, http.StatusBadRequest) - return err + return model.NewAppError("updatePassword", "api.user.update_password.oauth.app_error", nil, "auth_service="+user.AuthService, http.StatusBadRequest) } if err := a.DoubleCheckPassword(user, currentPassword); err != nil { @@ -944,9 +942,9 @@ func (a *App) UpdateActive(c request.CTX, user *model.User, active bool) (*model case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("UpdateActive", "app.user.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpdateActive", "app.user.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("UpdateActive", "app.user.update.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateActive", "app.user.update.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } ruser := userUpdate.New @@ -971,7 +969,7 @@ func (a *App) UpdateActive(c request.CTX, user *model.User, active bool) (*model func (a *App) DeactivateGuests(c *request.Context) *model.AppError { userIDs, err := a.ch.srv.userService.DeactivateAllGuests() if err != nil { - return model.NewAppError("DeactivateGuests", "app.user.update_active_for_multiple_users.updating.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeactivateGuests", "app.user.update_active_for_multiple_users.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, userID := range userIDs { @@ -1061,9 +1059,9 @@ func (a *App) UpdateUserAuth(userID string, userAuth *model.UserAuth) (*model.Us var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return nil, model.NewAppError("UpdateUserAuth", "app.user.update_auth_data.email_exists.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpdateUserAuth", "app.user.update_auth_data.email_exists.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("UpdateUserAuth", "app.user.update_auth_data.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateUserAuth", "app.user.update_auth_data.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1104,7 +1102,7 @@ func (a *App) isUniqueToGroupNames(val string) *model.AppError { var notFoundErr *store.ErrNotFound group, err := a.Srv().Store.Group().GetByName(val, model.GroupSearchOpts{}) if err != nil && !errors.As(err, ¬FoundErr) { - return model.NewAppError("", "app.user.get_by_name_failure", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("", "app.user.get_by_name_failure", nil, "", http.StatusInternalServerError).Wrap(err) } if group != nil { return model.NewAppError("", "app.user.group_name_conflict", nil, "", http.StatusBadRequest) @@ -1118,9 +1116,9 @@ func (a *App) UpdateUser(c request.CTX, user *model.User, sendNotifications bool var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("UpdateUser", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("UpdateUser", MissingAccountError, nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("UpdateUser", "app.user.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateUser", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1176,14 +1174,14 @@ func (a *App) UpdateUser(c request.CTX, user *model.User, sendNotifications bool case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("UpdateUser", "app.user.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpdateUser", "app.user.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &conErr): - if cErr, ok := err.(*store.ErrConflict); ok && cErr.Resource == "Username" { - return nil, model.NewAppError("UpdateUser", "app.user.save.username_exists.app_error", nil, "", http.StatusBadRequest) + if conErr.Resource == "Username" { + return nil, model.NewAppError("UpdateUser", "app.user.save.username_exists.app_error", nil, "", http.StatusBadRequest).Wrap(err) } - return nil, model.NewAppError("UpdateUser", "app.user.save.email_exists.app_error", nil, "", http.StatusBadRequest) + return nil, model.NewAppError("UpdateUser", "app.user.save.email_exists.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("UpdateUser", "app.user.update.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateUser", "app.user.update.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1294,7 +1292,7 @@ func (a *App) UpdatePassword(user *model.User, newPassword string) *model.AppErr hashedPassword := model.HashPassword(newPassword) if err := a.Srv().Store.User().UpdatePassword(user.Id, hashedPassword); err != nil { - return model.NewAppError("UpdatePassword", "api.user.update_password.failed.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdatePassword", "api.user.update_password.failed.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.InvalidateCacheForUser(user.Id) @@ -1327,7 +1325,7 @@ func (a *App) UpdateHashedPasswordByUserId(userID, newHashedPassword string) *mo func (a *App) UpdateHashedPassword(user *model.User, newHashedPassword string) *model.AppError { if err := a.Srv().Store.User().UpdatePassword(user.Id, newHashedPassword); err != nil { - return model.NewAppError("UpdatePassword", "api.user.update_password.failed.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdatePassword", "api.user.update_password.failed.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.InvalidateCacheForUser(user.Id) @@ -1428,7 +1426,7 @@ func (a *App) CreatePasswordRecoveryToken(userID, email string) (*model.Token, * case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("CreatePasswordRecoveryToken", "app.recover.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreatePasswordRecoveryToken", "app.recover.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1438,7 +1436,7 @@ func (a *App) CreatePasswordRecoveryToken(userID, email string) (*model.Token, * func (a *App) GetPasswordRecoveryToken(token string) (*model.Token, *model.AppError) { rtoken, err := a.Srv().Store.Token().GetByToken(token) if err != nil { - return nil, model.NewAppError("GetPasswordRecoveryToken", "api.user.reset_password.invalid_link.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetPasswordRecoveryToken", "api.user.reset_password.invalid_link.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if rtoken.Type != TokenTypePasswordRecovery { return nil, model.NewAppError("GetPasswordRecoveryToken", "api.user.reset_password.broken_token.app_error", nil, "", http.StatusBadRequest) @@ -1459,7 +1457,7 @@ func (a *App) GetTokenById(token string) (*model.Token, *model.AppError) { status = http.StatusInternalServerError } - return nil, model.NewAppError("GetTokenById", "api.user.create_user.signup_link_invalid.app_error", nil, err.Error(), status) + return nil, model.NewAppError("GetTokenById", "api.user.create_user.signup_link_invalid.app_error", nil, "", status).Wrap(err) } return rtoken, nil @@ -1468,7 +1466,7 @@ func (a *App) GetTokenById(token string) (*model.Token, *model.AppError) { func (a *App) DeleteToken(token *model.Token) *model.AppError { err := a.Srv().Store.Token().Delete(token.Token) if err != nil { - return model.NewAppError("DeleteToken", "app.recover.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteToken", "app.recover.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } @@ -1512,9 +1510,9 @@ func (a *App) UpdateUserRolesWithUser(c request.CTX, user *model.User, newRoles case errors.As(result.NErr, &appErr): return nil, appErr case errors.As(result.NErr, &invErr): - return nil, model.NewAppError("UpdateUserRoles", "app.user.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("UpdateUserRoles", "app.user.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(result.NErr) default: - return nil, model.NewAppError("UpdateUserRoles", "app.user.update.finding.app_error", nil, result.NErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateUserRoles", "app.user.update.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr) } } ruser := result.Data.(*model.UserUpdate).New @@ -1548,52 +1546,52 @@ func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.A } if err := a.Srv().Store.Session().PermanentDeleteSessionsByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.session.permanent_delete_sessions_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.session.permanent_delete_sessions_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.UserAccessToken().DeleteAllForUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.user_access_token.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.user_access_token.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.OAuth().PermanentDeleteAuthDataByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.oauth.permanent_delete_auth_data_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.oauth.permanent_delete_auth_data_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Webhook().PermanentDeleteIncomingByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.webhooks.permanent_delete_incoming_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.webhooks.permanent_delete_incoming_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Webhook().PermanentDeleteOutgoingByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.webhooks.permanent_delete_outgoing_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.webhooks.permanent_delete_outgoing_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Command().PermanentDeleteByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.user.permanentdeleteuser.internal_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.user.permanentdeleteuser.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Preference().PermanentDeleteByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.preference.permanent_delete_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.preference.permanent_delete_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Channel().PermanentDeleteMembersByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.channel.permanent_delete_members_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.channel.permanent_delete_members_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Group().PermanentDeleteMembersByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.group.permanent_delete_members_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.group.permanent_delete_members_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Post().PermanentDeleteByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.post.permanent_delete_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.post.permanent_delete_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Bot().PermanentDelete(user.Id); err != nil { var invErr *store.ErrInvalidInput switch { case errors.As(err, &invErr): - return model.NewAppError("PermanentDeleteUser", "app.bot.permenent_delete.bad_id", map[string]any{"user_id": invErr.Value}, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("PermanentDeleteUser", "app.bot.permenent_delete.bad_id", map[string]any{"user_id": invErr.Value}, "", http.StatusBadRequest).Wrap(err) default: // last fallback in case it doesn't map to an existing app error. - return model.NewAppError("PermanentDeleteUser", "app.bot.permanent_delete.internal_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.bot.permanent_delete.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1630,19 +1628,19 @@ func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.A } if _, err := a.Srv().Store.FileInfo().PermanentDeleteByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.file_info.permanent_delete_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.file_info.permanent_delete_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.User().PermanentDelete(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.user.permanent_delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.user.permanent_delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Audit().PermanentDeleteByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.audit.permanent_delete_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.audit.permanent_delete_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := a.Srv().Store.Team().RemoveAllMembersByUser(user.Id); err != nil { - return model.NewAppError("PermanentDeleteUser", "app.team.remove_member.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteUser", "app.team.remove_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } c.Logger().Warn("Permanently deleted account", mlog.String("user_email", user.Email), mlog.String("user_id", user.Id)) @@ -1653,7 +1651,7 @@ func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.A func (a *App) PermanentDeleteAllUsers(c *request.Context) *model.AppError { users, err := a.Srv().Store.User().GetAll() if err != nil { - return model.NewAppError("PermanentDeleteAllUsers", "app.user.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("PermanentDeleteAllUsers", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, user := range users { a.PermanentDeleteUser(c, user) @@ -1669,7 +1667,7 @@ func (a *App) SendEmailVerification(user *model.User, newEmail, redirect string) case errors.Is(err, email.CreateEmailTokenError): return model.NewAppError("CreateVerifyEmailToken", "api.user.create_email_token.error", nil, "", http.StatusInternalServerError) default: - return model.NewAppError("CreateVerifyEmailToken", "app.recover.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("CreateVerifyEmailToken", "app.recover.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -1679,14 +1677,14 @@ func (a *App) SendEmailVerification(user *model.User, newEmail, redirect string) } 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 model.NewAppError("SendVerifyEmail", "api.user.send_verify_email_and_forget.failed.error", nil, "", http.StatusInternalServerError).Wrap(eErr) } return nil } if err := a.Srv().EmailService.SendEmailChangeVerifyEmail(newEmail, user.Locale, a.GetSiteURL(), token.Token); err != nil { - return model.NewAppError("sendEmailChangeVerifyEmail", "api.user.send_email_change_verify_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("sendEmailChangeVerifyEmail", "api.user.send_email_change_verify_email_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -1739,7 +1737,7 @@ func (a *App) VerifyEmailFromToken(c request.CTX, userSuppliedTokenString string func (a *App) GetVerifyEmailToken(token string) (*model.Token, *model.AppError) { rtoken, err := a.Srv().Store.Token().GetByToken(token) if err != nil { - return nil, model.NewAppError("GetVerifyEmailToken", "api.user.verify_email.bad_link.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, model.NewAppError("GetVerifyEmailToken", "api.user.verify_email.bad_link.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if rtoken.Type != TokenTypeVerifyEmail { return nil, model.NewAppError("GetVerifyEmailToken", "api.user.verify_email.broken_token.app_error", nil, "", http.StatusBadRequest) @@ -1754,7 +1752,7 @@ func (a *App) GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions) ViewRestrictions: viewRestrictions, }) if err != nil { - return nil, model.NewAppError("GetTotalUsersStats", "app.user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetTotalUsersStats", "app.user.get_total_users_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } stats := &model.UsersStats{ TotalUsersCount: count, @@ -1766,7 +1764,7 @@ func (a *App) GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions) func (a *App) GetFilteredUsersStats(options *model.UserCountOptions) (*model.UsersStats, *model.AppError) { count, err := a.Srv().Store.User().Count(*options) if err != nil { - return nil, model.NewAppError("GetFilteredUsersStats", "app.user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetFilteredUsersStats", "app.user.get_total_users_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } stats := &model.UsersStats{ TotalUsersCount: count, @@ -1776,7 +1774,7 @@ func (a *App) GetFilteredUsersStats(options *model.UserCountOptions) (*model.Use func (a *App) VerifyUserEmail(userID, email string) *model.AppError { if _, err := a.Srv().Store.User().VerifyEmail(userID, email); err != nil { - return model.NewAppError("VerifyUserEmail", "app.user.verify_email.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("VerifyUserEmail", "app.user.verify_email.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.InvalidateCacheForUser(userID) @@ -1818,7 +1816,7 @@ func (a *App) SearchUsersInChannel(channelID string, term string, options *model term = strings.TrimSpace(term) users, err := a.Srv().Store.User().SearchInChannel(channelID, term, options) if err != nil { - return nil, model.NewAppError("SearchUsersInChannel", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchUsersInChannel", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, user := range users { a.SanitizeProfile(user, options.IsAdmin) @@ -1831,7 +1829,7 @@ func (a *App) SearchUsersNotInChannel(teamID string, channelID string, term stri term = strings.TrimSpace(term) users, err := a.Srv().Store.User().SearchNotInChannel(teamID, channelID, term, options) if err != nil { - return nil, model.NewAppError("SearchUsersNotInChannel", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchUsersNotInChannel", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, user := range users { @@ -1846,7 +1844,7 @@ func (a *App) SearchUsersInTeam(teamID, term string, options *model.UserSearchOp users, err := a.Srv().Store.User().Search(teamID, term, options) if err != nil { - return nil, model.NewAppError("SearchUsersInTeam", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchUsersInTeam", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, user := range users { @@ -1860,7 +1858,7 @@ func (a *App) SearchUsersNotInTeam(notInTeamId string, term string, options *mod term = strings.TrimSpace(term) users, err := a.Srv().Store.User().SearchNotInTeam(notInTeamId, term, options) if err != nil { - return nil, model.NewAppError("SearchUsersNotInTeam", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchUsersNotInTeam", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, user := range users { @@ -1874,7 +1872,7 @@ func (a *App) SearchUsersWithoutTeam(term string, options *model.UserSearchOptio term = strings.TrimSpace(term) users, err := a.Srv().Store.User().SearchWithoutTeam(term, options) if err != nil { - return nil, model.NewAppError("SearchUsersWithoutTeam", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchUsersWithoutTeam", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, user := range users { @@ -1888,7 +1886,7 @@ func (a *App) SearchUsersInGroup(groupID string, term string, options *model.Use term = strings.TrimSpace(term) users, err := a.Srv().Store.User().SearchInGroup(groupID, term, options) if err != nil { - return nil, model.NewAppError("SearchUsersInGroup", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchUsersInGroup", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, user := range users { @@ -1902,7 +1900,7 @@ func (a *App) SearchUsersNotInGroup(groupID string, term string, options *model. term = strings.TrimSpace(term) users, err := a.Srv().Store.User().SearchNotInGroup(groupID, term, options) if err != nil { - return nil, model.NewAppError("SearchUsersNotInGroup", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("SearchUsersNotInGroup", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, user := range users { @@ -1917,7 +1915,7 @@ func (a *App) AutocompleteUsersInChannel(teamID string, channelID string, term s autocomplete, err := a.Srv().Store.User().AutocompleteUsersInChannel(teamID, channelID, term, options) if err != nil { - return nil, model.NewAppError("AutocompleteUsersInChannel", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AutocompleteUsersInChannel", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, user := range autocomplete.InChannel { @@ -1936,7 +1934,7 @@ func (a *App) AutocompleteUsersInTeam(teamID string, term string, options *model users, err := a.Srv().Store.User().Search(teamID, term, options) if err != nil { - return nil, model.NewAppError("AutocompleteUsersInTeam", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("AutocompleteUsersInTeam", "app.user.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, user := range users { @@ -1951,7 +1949,7 @@ func (a *App) AutocompleteUsersInTeam(teamID string, term string, options *model func (a *App) UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError { oauthUser, err1 := provider.GetUserFromJSON(userData, tokenUser) if err1 != nil { - return model.NewAppError("UpdateOAuthUserAttrs", "api.user.update_oauth_user_attrs.get_user.app_error", map[string]any{"Service": service}, err1.Error(), http.StatusBadRequest) + return model.NewAppError("UpdateOAuthUserAttrs", "api.user.update_oauth_user_attrs.get_user.app_error", map[string]any{"Service": service}, "", http.StatusBadRequest).Wrap(err1) } userAttrsChanged := false @@ -1991,9 +1989,9 @@ func (a *App) UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provide case errors.As(err, &appErr): return appErr case errors.As(err, &invErr): - return model.NewAppError("UpdateOAuthUserAttrs", "app.user.update.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("UpdateOAuthUserAttrs", "app.user.update.find.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return model.NewAppError("UpdateOAuthUserAttrs", "app.user.update.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdateOAuthUserAttrs", "app.user.update.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -2087,7 +2085,7 @@ func (a *App) UserCanSeeOtherUser(userID string, otherUserId string) (bool, *mod if len(restrictions.Teams) > 0 { result, err := a.Srv().Store.Team().UserBelongsToTeams(otherUserId, restrictions.Teams) if err != nil { - return false, model.NewAppError("UserCanSeeOtherUser", "app.team.user_belongs_to_teams.app_error", nil, err.Error(), http.StatusInternalServerError) + return false, model.NewAppError("UserCanSeeOtherUser", "app.team.user_belongs_to_teams.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if result { return true, nil @@ -2110,7 +2108,7 @@ func (a *App) UserCanSeeOtherUser(userID string, otherUserId string) (bool, *mod func (a *App) userBelongsToChannels(userID string, channelIDs []string) (bool, *model.AppError) { belongs, err := a.Srv().Store.Channel().UserBelongsToChannels(userID, channelIDs) if err != nil { - return false, model.NewAppError("userBelongsToChannels", "app.channel.user_belongs_to_channels.app_error", nil, err.Error(), http.StatusInternalServerError) + return false, model.NewAppError("userBelongsToChannels", "app.channel.user_belongs_to_channels.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return belongs, nil @@ -2123,7 +2121,7 @@ func (a *App) GetViewUsersRestrictions(userID string) (*model.ViewUsersRestricti teamIDs, nErr := a.Srv().Store.Team().GetUserTeamIds(userID, true) if nErr != nil { - return nil, model.NewAppError("GetViewUsersRestrictions", "app.team.get_user_team_ids.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetViewUsersRestrictions", "app.team.get_user_team_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } teamIDsWithPermission := []string{} @@ -2135,7 +2133,7 @@ func (a *App) GetViewUsersRestrictions(userID string) (*model.ViewUsersRestricti userChannelMembers, err := a.Srv().Store.Channel().GetAllChannelMembersForUser(userID, true, true) if err != nil { - return nil, model.NewAppError("GetViewUsersRestrictions", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetViewUsersRestrictions", "app.channel.get_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } channelIDs := []string{} @@ -2152,11 +2150,11 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor nErr := a.ch.srv.userService.PromoteGuestToUser(user) a.InvalidateCacheForUser(user.Id) if nErr != nil { - return model.NewAppError("PromoteGuestToUser", "app.user.promote_guest.user_update.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("PromoteGuestToUser", "app.user.promote_guest.user_update.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } userTeams, nErr := a.Srv().Store.Team().GetTeamsByUserId(user.Id) if nErr != nil { - return model.NewAppError("PromoteGuestToUser", "app.team.get_all.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("PromoteGuestToUser", "app.team.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } for _, team := range userTeams { @@ -2212,7 +2210,7 @@ func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError demotedUser, nErr := a.ch.srv.userService.DemoteUserToGuest(user) a.InvalidateCacheForUser(user.Id) if nErr != nil { - return model.NewAppError("DemoteUserToGuest", "app.user.demote_user_to_guest.user_update.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("DemoteUserToGuest", "app.user.demote_user_to_guest.user_update.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } a.sendUpdatedUserEvent(*demotedUser) @@ -2287,7 +2285,7 @@ func (a *App) invalidateUserCacheAndPublish(userID string) { func (a *App) GetKnownUsers(userID string) ([]string, *model.AppError) { users, err := a.Srv().Store.User().GetKnownUsers(userID) if err != nil { - return nil, model.NewAppError("GetKnownUsers", "app.user.get_known_users.get_users.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetKnownUsers", "app.user.get_known_users.get_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil @@ -2300,9 +2298,9 @@ func (a *App) ConvertBotToUser(c request.CTX, bot *model.Bot, userPatch *model.U var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return nil, model.NewAppError("ConvertBotToUser", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("ConvertBotToUser", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nErr) default: - return nil, model.NewAppError("ConvertBotToUser", "app.user.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ConvertBotToUser", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -2330,7 +2328,7 @@ func (a *App) ConvertBotToUser(c request.CTX, bot *model.Bot, userPatch *model.U 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, appErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("ConvertBotToUser", "app.user.convert_bot_to_user.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr) } return user, nil @@ -2390,7 +2388,7 @@ func (a *App) GetThreadsForUser(userID, teamID string, options model.GetUserThre } if err := eg.Wait(); err != nil { - return nil, model.NewAppError("GetThreadsForUser", "app.user.get_threads_for_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetThreadsForUser", "app.user.get_threads_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if options.Unread { @@ -2408,7 +2406,7 @@ func (a *App) GetThreadsForUser(userID, teamID string, options model.GetUserThre func (a *App) GetThreadMembershipForUser(userId, threadId string) (*model.ThreadMembership, *model.AppError) { threadMembership, err := a.Srv().Store.Thread().GetMembershipForUser(userId, threadId) if err != nil { - return nil, model.NewAppError("GetThreadMembershipForUser", "app.user.get_thread_membership_for_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetThreadMembershipForUser", "app.user.get_thread_membership_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if threadMembership == nil { return nil, model.NewAppError("GetThreadMembershipForUser", "app.user.get_thread_membership_for_user.not_found", nil, "thread membership not found/followed", http.StatusNotFound) @@ -2419,7 +2417,7 @@ func (a *App) GetThreadMembershipForUser(userId, threadId string) (*model.Thread func (a *App) GetThreadForUser(teamID string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, *model.AppError) { thread, err := a.Srv().Store.Thread().GetThreadForUser(teamID, threadMembership, extended) if err != nil { - return nil, model.NewAppError("GetThreadForUser", "app.user.get_threads_for_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetThreadForUser", "app.user.get_threads_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if thread == nil { return nil, model.NewAppError("GetThreadForUser", "app.user.get_threads_for_user.not_found", nil, "thread not found/followed", http.StatusNotFound) @@ -2432,7 +2430,7 @@ func (a *App) GetThreadForUser(teamID string, threadMembership *model.ThreadMemb func (a *App) UpdateThreadsReadForUser(userID, teamID string) *model.AppError { nErr := a.Srv().Store.Thread().MarkAllAsReadByTeam(userID, teamID) if nErr != nil { - return model.NewAppError("UpdateThreadsReadForUser", "app.user.update_threads_read_for_user.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdateThreadsReadForUser", "app.user.update_threads_read_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } message := model.NewWebSocketEvent(model.WebsocketEventThreadReadChanged, teamID, "", userID, nil) a.Publish(message) @@ -2449,11 +2447,11 @@ func (a *App) UpdateThreadFollowForUser(userID, teamID, threadID string, state b } _, err := a.Srv().Store.Thread().MaintainMembership(userID, threadID, opts) if err != nil { - return model.NewAppError("UpdateThreadFollowForUser", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdateThreadFollowForUser", "app.user.update_thread_follow_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } thread, err := a.Srv().Store.Thread().Get(threadID) if err != nil { - return model.NewAppError("UpdateThreadFollowForUser", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdateThreadFollowForUser", "app.user.update_thread_follow_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } replyCount := int64(0) if thread != nil { @@ -2477,7 +2475,7 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(c request.CTX, userID, tea } tm, err := a.Srv().Store.Thread().MaintainMembership(userID, threadID, opts) if err != nil { - return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } post, appErr := a.GetSinglePost(threadID, false) @@ -2495,7 +2493,7 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(c request.CTX, userID, tea tm.LastViewed = post.CreateAt - 1 _, err = a.Srv().Store.Thread().UpdateMembership(tm) if err != nil { - return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } message := model.NewWebSocketEvent(model.WebsocketEventThreadUpdated, teamID, "", userID, nil) @@ -2505,7 +2503,7 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(c request.CTX, userID, tea if errors.As(err, &errNotFound) { return nil } - return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.sanitizeProfiles(userThread.Participants, false) userThread.Post.SanitizeProps() @@ -2552,13 +2550,13 @@ func (a *App) UpdateThreadReadForUser(c request.CTX, currentSessionId, userID, t } membership, storeErr := a.Srv().Store.Thread().MaintainMembership(userID, threadID, opts) if storeErr != nil { - return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, storeErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(storeErr) } previousUnreadMentions := membership.UnreadMentions previousUnreadReplies, nErr := a.Srv().Store.Thread().GetThreadUnreadReplyCount(membership) if nErr != nil { - return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } post, err := a.GetSinglePost(threadID, false) @@ -2571,14 +2569,14 @@ func (a *App) UpdateThreadReadForUser(c request.CTX, currentSessionId, userID, t } _, nErr = a.Srv().Store.Thread().UpdateMembership(membership) if nErr != nil { - return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } membership.LastViewed = timestamp nErr = a.Srv().Store.Thread().MarkAsRead(userID, threadID, timestamp) if nErr != nil { - return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } thread, err := a.GetThreadForUser(teamID, membership, false) if err != nil { @@ -2605,7 +2603,7 @@ func (a *App) UpdateThreadReadForUser(c request.CTX, currentSessionId, userID, t func (a *App) GetUsersWithInvalidEmails(page int, perPage int) ([]*model.User, *model.AppError) { users, err := a.Srv().Store.User().GetUsersWithInvalidEmails(page, perPage, *a.Config().TeamSettings.RestrictCreationToDomains) if err != nil { - return nil, model.NewAppError("GetUsersPage", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUsersPage", "app.user.get_profiles.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users, nil diff --git a/app/user_terms_of_service.go b/app/user_terms_of_service.go index d1e3eef45e..d201bd274d 100644 --- a/app/user_terms_of_service.go +++ b/app/user_terms_of_service.go @@ -17,9 +17,9 @@ func (a *App) GetUserTermsOfService(userID string) (*model.UserTermsOfService, * var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetUserTermsOfService", "app.user_terms_of_service.get_by_user.no_rows.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetUserTermsOfService", "app.user_terms_of_service.get_by_user.no_rows.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetUserTermsOfService", "app.user_terms_of_service.get_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetUserTermsOfService", "app.user_terms_of_service.get_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -39,12 +39,12 @@ func (a *App) SaveUserTermsOfService(userID, termsOfServiceId string, accepted b case errors.As(err, &appErr): return appErr default: - return model.NewAppError("SaveUserTermsOfService", "app.user_terms_of_service.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SaveUserTermsOfService", "app.user_terms_of_service.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } } else { if err := a.Srv().Store.UserTermsOfService().Delete(userID, termsOfServiceId); err != nil { - return model.NewAppError("SaveUserTermsOfService", "app.user_terms_of_service.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SaveUserTermsOfService", "app.user_terms_of_service.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } diff --git a/app/webhook.go b/app/webhook.go index e8b201f056..e519d74353 100644 --- a/app/webhook.go +++ b/app/webhook.go @@ -39,7 +39,7 @@ func (a *App) handleWebhookEvents(c request.CTX, post *model.Post, team *model.T hooks, err := a.Srv().Store.Webhook().GetOutgoingByTeam(team.Id, -1, -1) if err != nil { - return model.NewAppError("handleWebhookEvents", "app.webhooks.get_outgoing_by_team.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("handleWebhookEvents", "app.webhooks.get_outgoing_by_team.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if len(hooks) == 0 { @@ -349,9 +349,9 @@ func (a *App) CreateIncomingWebhookForChannel(creatorId string, channel *model.C case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("CreateIncomingWebhookForChannel", "app.webhooks.save_incoming.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateIncomingWebhookForChannel", "app.webhooks.save_incoming.existing.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("CreateIncomingWebhookForChannel", "app.webhooks.save_incoming.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateIncomingWebhookForChannel", "app.webhooks.save_incoming.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -383,7 +383,7 @@ func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) newWebhook, err := a.Srv().Store.Webhook().UpdateIncoming(updatedHook) if err != nil { - return nil, model.NewAppError("UpdateIncomingWebhook", "app.webhooks.update_incoming.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateIncomingWebhook", "app.webhooks.update_incoming.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.invalidateCacheForWebhook(oldHook.Id) return newWebhook, nil @@ -395,7 +395,7 @@ func (a *App) DeleteIncomingWebhook(hookID string) *model.AppError { } if err := a.Srv().Store.Webhook().DeleteIncoming(hookID, model.GetMillis()); err != nil { - return model.NewAppError("DeleteIncomingWebhook", "app.webhooks.delete_incoming.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteIncomingWebhook", "app.webhooks.delete_incoming.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } a.invalidateCacheForWebhook(hookID) @@ -413,9 +413,9 @@ func (a *App) GetIncomingWebhook(hookID string) (*model.IncomingWebhook, *model. var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetIncomingWebhook", "app.webhooks.get_incoming.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetIncomingWebhook", "app.webhooks.get_incoming.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetIncomingWebhook", "app.webhooks.get_incoming.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetIncomingWebhook", "app.webhooks.get_incoming.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -433,7 +433,7 @@ func (a *App) GetIncomingWebhooksForTeamPageByUser(teamID string, userID string, webhooks, err := a.Srv().Store.Webhook().GetIncomingByTeamByUser(teamID, userID, page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetIncomingWebhooksForTeamPage", "app.webhooks.get_incoming_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetIncomingWebhooksForTeamPage", "app.webhooks.get_incoming_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return webhooks, nil @@ -446,7 +446,7 @@ func (a *App) GetIncomingWebhooksPageByUser(userID string, page, perPage int) ([ webhooks, err := a.Srv().Store.Webhook().GetIncomingListByUser(userID, page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetIncomingWebhooksPageByUser", "app.webhooks.get_incoming_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetIncomingWebhooksPageByUser", "app.webhooks.get_incoming_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return webhooks, nil @@ -467,9 +467,9 @@ func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.Outgoin var nfErr *store.ErrNotFound switch { case errors.As(errCh, &nfErr): - return nil, model.NewAppError("CreateOutgoingWebhook", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("CreateOutgoingWebhook", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(errCh) default: - return nil, model.NewAppError("CreateOutgoingWebhook", "app.channel.get.find.app_error", nil, errCh.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateOutgoingWebhook", "app.channel.get.find.app_error", nil, "", http.StatusInternalServerError).Wrap(errCh) } } @@ -486,7 +486,7 @@ func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.Outgoin allHooks, err := a.Srv().Store.Webhook().GetOutgoingByTeam(hook.TeamId, -1, -1) if err != nil { - return nil, model.NewAppError("CreateOutgoingWebhook", "app.webhooks.get_outgoing_by_team.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateOutgoingWebhook", "app.webhooks.get_outgoing_by_team.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, existingOutHook := range allHooks { urlIntersect := utils.StringArrayIntersection(existingOutHook.CallbackURLs, hook.CallbackURLs) @@ -505,9 +505,9 @@ func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.Outgoin case errors.As(err, &appErr): return nil, appErr case errors.As(err, &invErr): - return nil, model.NewAppError("CreateOutgoingWebhook", "app.webhooks.save_outgoing.override.app_error", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateOutgoingWebhook", "app.webhooks.save_outgoing.override.app_error", nil, "", http.StatusBadRequest).Wrap(err) default: - return nil, model.NewAppError("CreateOutgoingWebhook", "app.webhooks.save_outgoing.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateOutgoingWebhook", "app.webhooks.save_outgoing.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -538,7 +538,7 @@ func (a *App) UpdateOutgoingWebhook(c request.CTX, oldHook, updatedHook *model.O allHooks, err := a.Srv().Store.Webhook().GetOutgoingByTeam(oldHook.TeamId, -1, -1) if err != nil { - return nil, model.NewAppError("UpdateOutgoingWebhook", "app.webhooks.get_outgoing_by_team.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateOutgoingWebhook", "app.webhooks.get_outgoing_by_team.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, existingOutHook := range allHooks { @@ -558,7 +558,7 @@ func (a *App) UpdateOutgoingWebhook(c request.CTX, oldHook, updatedHook *model.O webhook, err := a.Srv().Store.Webhook().UpdateOutgoing(updatedHook) if err != nil { - return nil, model.NewAppError("UpdateOutgoingWebhook", "app.webhooks.update_outgoing.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("UpdateOutgoingWebhook", "app.webhooks.update_outgoing.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return webhook, nil @@ -574,9 +574,9 @@ func (a *App) GetOutgoingWebhook(hookID string) (*model.OutgoingWebhook, *model. var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetOutgoingWebhook", "app.webhooks.get_outgoing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetOutgoingWebhook", "app.webhooks.get_outgoing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetOutgoingWebhook", "app.webhooks.get_outgoing.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetOutgoingWebhook", "app.webhooks.get_outgoing.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -594,7 +594,7 @@ func (a *App) GetOutgoingWebhooksPageByUser(userID string, page, perPage int) ([ webhooks, err := a.Srv().Store.Webhook().GetOutgoingListByUser(userID, page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetOutgoingWebhooksPageByUser", "app.webhooks.get_outgoing_by_channel.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetOutgoingWebhooksPageByUser", "app.webhooks.get_outgoing_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return webhooks, nil @@ -607,7 +607,7 @@ func (a *App) GetOutgoingWebhooksForChannelPageByUser(channelID string, userID s webhooks, err := a.Srv().Store.Webhook().GetOutgoingByChannelByUser(channelID, userID, page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "app.webhooks.get_outgoing_by_channel.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "app.webhooks.get_outgoing_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return webhooks, nil @@ -624,7 +624,7 @@ func (a *App) GetOutgoingWebhooksForTeamPageByUser(teamID string, userID string, webhooks, err := a.Srv().Store.Webhook().GetOutgoingByTeamByUser(teamID, userID, page*perPage, perPage) if err != nil { - return nil, model.NewAppError("GetOutgoingWebhooksForTeamPageByUser", "app.webhooks.get_outgoing_by_team.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetOutgoingWebhooksForTeamPageByUser", "app.webhooks.get_outgoing_by_team.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return webhooks, nil @@ -636,7 +636,7 @@ func (a *App) DeleteOutgoingWebhook(hookID string) *model.AppError { } if err := a.Srv().Store.Webhook().DeleteOutgoing(hookID, model.GetMillis()); err != nil { - return model.NewAppError("DeleteOutgoingWebhook", "app.webhooks.delete_outgoing.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("DeleteOutgoingWebhook", "app.webhooks.delete_outgoing.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil @@ -651,7 +651,7 @@ func (a *App) RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.Out webhook, err := a.Srv().Store.Webhook().UpdateOutgoing(hook) if err != nil { - return nil, model.NewAppError("RegenOutgoingWebhookToken", "app.webhooks.update_outgoing.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("RegenOutgoingWebhookToken", "app.webhooks.update_outgoing.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return webhook, nil @@ -684,7 +684,7 @@ func (a *App) HandleIncomingWebhook(c *request.Context, hookID string, req *mode var hook *model.IncomingWebhook result := <-hchan if result.NErr != nil { - return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.invalid.app_error", nil, result.NErr.Error(), http.StatusBadRequest) + return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.invalid.app_error", nil, "", http.StatusBadRequest).Wrap(result.NErr) } hook = result.Data.(*model.IncomingWebhook) @@ -716,7 +716,7 @@ func (a *App) HandleIncomingWebhook(c *request.Context, hookID string, req *mode if channelName[0] == '@' { result, nErr := a.Srv().Store.User().GetByUsername(channelName[1:]) if nErr != nil { - return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, nErr.Error(), http.StatusBadRequest) + return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) } ch, err := a.GetOrCreateDirectChannel(c, hook.UserId, result.Id) if err != nil { @@ -745,9 +745,9 @@ func (a *App) HandleIncomingWebhook(c *request.Context, hookID string, req *mode var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return model.NewAppError("HandleIncomingWebhook", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("HandleIncomingWebhook", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return model.NewAppError("HandleIncomingWebhook", "app.channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("HandleIncomingWebhook", "app.channel.get.find.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } } @@ -758,9 +758,9 @@ func (a *App) HandleIncomingWebhook(c *request.Context, hookID string, req *mode var nfErr *store.ErrNotFound switch { case errors.As(result2.NErr, &nfErr): - return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "", http.StatusNotFound).Wrap(result2.NErr) default: - return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, result2.NErr.Error(), http.StatusInternalServerError) + return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "", http.StatusInternalServerError).Wrap(result2.NErr) } } channel = result2.Data.(*model.Channel) @@ -772,7 +772,7 @@ func (a *App) HandleIncomingWebhook(c *request.Context, hookID string, req *mode result = <-uchan if result.NErr != nil { - return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, result.NErr.Error(), http.StatusForbidden) + return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, "", http.StatusForbidden).Wrap(result.NErr) } if channel.Type != model.ChannelTypeOpen && !a.HasPermissionToChannel(c, hook.UserId, channel.Id, model.PermissionReadChannel) { @@ -807,11 +807,11 @@ func (a *App) CreateCommandWebhook(commandID string, args *model.CommandArgs) (* var appErr *model.AppError switch { case errors.As(err, &invErr): - return nil, model.NewAppError("CreateCommandWebhook", "app.command_webhook.create_command_webhook.existing", nil, invErr.Error(), http.StatusBadRequest) + return nil, model.NewAppError("CreateCommandWebhook", "app.command_webhook.create_command_webhook.existing", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): return nil, appErr default: - return nil, model.NewAppError("CreateCommandWebhook", "app.command_webhook.create_command_webhook.internal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateCommandWebhook", "app.command_webhook.create_command_webhook.internal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -828,9 +828,9 @@ func (a *App) HandleCommandWebhook(c *request.Context, hookID string, response * var nfErr *store.ErrNotFound switch { case errors.As(nErr, &nfErr): - return model.NewAppError("HandleCommandWebhook", "app.command_webhook.get.missing", map[string]any{"hook_id": hookID}, nfErr.Error(), http.StatusNotFound) + return model.NewAppError("HandleCommandWebhook", "app.command_webhook.get.missing", map[string]any{"hook_id": hookID}, "", http.StatusNotFound).Wrap(nErr) default: - return model.NewAppError("HandleCommandWebhook", "app.command_webhook.get.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("HandleCommandWebhook", "app.command_webhook.get.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } @@ -841,7 +841,7 @@ func (a *App) HandleCommandWebhook(c *request.Context, hookID string, response * case errors.As(cmdErr, &appErr): return appErr default: - return model.NewAppError("HandleCommandWebhook", "web.command_webhook.command.app_error", nil, "err="+cmdErr.Error(), http.StatusBadRequest) + return model.NewAppError("HandleCommandWebhook", "web.command_webhook.command.app_error", nil, "", http.StatusBadRequest).Wrap(cmdErr) } } @@ -856,9 +856,9 @@ func (a *App) HandleCommandWebhook(c *request.Context, hookID string, response * var invErr *store.ErrInvalidInput switch { case errors.As(nErr, &invErr): - return model.NewAppError("HandleCommandWebhook", "app.command_webhook.try_use.invalid", nil, invErr.Error(), http.StatusBadRequest) + return model.NewAppError("HandleCommandWebhook", "app.command_webhook.try_use.invalid", nil, "", http.StatusBadRequest).Wrap(nErr) default: - return model.NewAppError("HandleCommandWebhook", "app.command_webhook.try_use.internal_error", nil, nErr.Error(), http.StatusInternalServerError) + return model.NewAppError("HandleCommandWebhook", "app.command_webhook.try_use.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } diff --git a/jobs/base_workers.go b/jobs/base_workers.go index 4517083415..60fa0465ef 100644 --- a/jobs/base_workers.go +++ b/jobs/base_workers.go @@ -81,7 +81,7 @@ func (worker *SimpleWorker) DoJob(job *model.Job) { err := worker.execute(job) if err != nil { mlog.Error("SimpleWorker: job execution error", mlog.String("worker", worker.name), mlog.String("job_id", job.Id), mlog.Err(err)) - worker.setJobError(job, model.NewAppError("DoJob", "app.user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)) + worker.setJobError(job, model.NewAppError("DoJob", "app.user.get_total_users_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err)) return } diff --git a/jobs/import_process/worker.go b/jobs/import_process/worker.go index 883d0e48cc..be09177006 100644 --- a/jobs/import_process/worker.go +++ b/jobs/import_process/worker.go @@ -61,7 +61,7 @@ func MakeWorker(jobServer *jobs.JobServer, app AppIface) model.Worker { importZipReader, err := zip.NewReader(importFile.(io.ReaderAt), importFileSize) if err != nil { - return model.NewAppError("ImportProcessWorker", "import_process.worker.do_job.open_file", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ImportProcessWorker", "import_process.worker.do_job.open_file", nil, "", http.StatusInternalServerError).Wrap(err) } // find JSONL import file. @@ -77,7 +77,7 @@ func MakeWorker(jobServer *jobs.JobServer, app AppIface) model.Worker { jsonFile, err = f.Open() if err != nil { - return model.NewAppError("ImportProcessWorker", "import_process.worker.do_job.open_file", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("ImportProcessWorker", "import_process.worker.do_job.open_file", nil, "", http.StatusInternalServerError).Wrap(err) } defer jsonFile.Close() diff --git a/jobs/jobs.go b/jobs/jobs.go index f1a4979d8c..fdc9dbd4c1 100644 --- a/jobs/jobs.go +++ b/jobs/jobs.go @@ -36,7 +36,7 @@ func (srv *JobServer) CreateJob(jobType string, jobData map[string]string) (*mod } if _, err := srv.Store.Job().Save(&job); err != nil { - return nil, model.NewAppError("CreateJob", "app.job.save.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("CreateJob", "app.job.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &job, nil @@ -48,9 +48,9 @@ func (srv *JobServer) GetJob(id string) (*model.Job, *model.AppError) { var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetJob", "app.job.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetJob", "app.job.get.app_error", nil, "", http.StatusNotFound).Wrap(err) default: - return nil, model.NewAppError("GetJob", "app.job.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetJob", "app.job.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -60,7 +60,7 @@ func (srv *JobServer) GetJob(id string) (*model.Job, *model.AppError) { func (srv *JobServer) ClaimJob(job *model.Job) (bool, *model.AppError) { updated, err := srv.Store.Job().UpdateStatusOptimistically(job.Id, model.JobStatusPending, model.JobStatusInProgress) if err != nil { - return false, model.NewAppError("ClaimJob", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return false, model.NewAppError("ClaimJob", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if updated && srv.metrics != nil { @@ -75,21 +75,21 @@ func (srv *JobServer) SetJobProgress(job *model.Job, progress int64) *model.AppE job.Progress = progress if _, err := srv.Store.Job().UpdateOptimistically(job, model.JobStatusInProgress); err != nil { - return model.NewAppError("SetJobProgress", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetJobProgress", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } func (srv *JobServer) SetJobWarning(job *model.Job) *model.AppError { if _, err := srv.Store.Job().UpdateStatus(job.Id, model.JobStatusWarning); err != nil { - return model.NewAppError("SetJobWarning", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetJobWarning", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } func (srv *JobServer) SetJobSuccess(job *model.Job) *model.AppError { if _, err := srv.Store.Job().UpdateStatus(job.Id, model.JobStatusSuccess); err != nil { - return model.NewAppError("SetJobSuccess", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetJobSuccess", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if srv.metrics != nil { @@ -103,7 +103,7 @@ func (srv *JobServer) SetJobError(job *model.Job, jobError *model.AppError) *mod if jobError == nil { _, err := srv.Store.Job().UpdateStatus(job.Id, model.JobStatusError) if err != nil { - return model.NewAppError("SetJobError", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetJobError", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if srv.metrics != nil { @@ -124,7 +124,7 @@ func (srv *JobServer) SetJobError(job *model.Job, jobError *model.AppError) *mod } updated, err := srv.Store.Job().UpdateOptimistically(job, model.JobStatusInProgress) if err != nil { - return model.NewAppError("SetJobError", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetJobError", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if updated && srv.metrics != nil { srv.metrics.DecrementJobActive(job.Type) @@ -133,7 +133,7 @@ func (srv *JobServer) SetJobError(job *model.Job, jobError *model.AppError) *mod if !updated { updated, err = srv.Store.Job().UpdateOptimistically(job, model.JobStatusCancelRequested) if err != nil { - return model.NewAppError("SetJobError", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetJobError", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if !updated { return model.NewAppError("SetJobError", "jobs.set_job_error.update.error", nil, "id="+job.Id, http.StatusInternalServerError) @@ -145,7 +145,7 @@ func (srv *JobServer) SetJobError(job *model.Job, jobError *model.AppError) *mod func (srv *JobServer) SetJobCanceled(job *model.Job) *model.AppError { if _, err := srv.Store.Job().UpdateStatus(job.Id, model.JobStatusCanceled); err != nil { - return model.NewAppError("SetJobCanceled", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetJobCanceled", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if srv.metrics != nil { @@ -157,7 +157,7 @@ func (srv *JobServer) SetJobCanceled(job *model.Job) *model.AppError { func (srv *JobServer) SetJobPending(job *model.Job) *model.AppError { if _, err := srv.Store.Job().UpdateStatus(job.Id, model.JobStatusPending); err != nil { - return model.NewAppError("SetJobPending", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("SetJobPending", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if srv.metrics != nil { @@ -171,7 +171,7 @@ func (srv *JobServer) UpdateInProgressJobData(job *model.Job) *model.AppError { job.Status = model.JobStatusInProgress job.LastActivityAt = model.GetMillis() if _, err := srv.Store.Job().UpdateOptimistically(job, model.JobStatusInProgress); err != nil { - return model.NewAppError("UpdateInProgressJobData", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("UpdateInProgressJobData", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } @@ -179,13 +179,13 @@ func (srv *JobServer) UpdateInProgressJobData(job *model.Job) *model.AppError { func (srv *JobServer) RequestCancellation(jobId string) *model.AppError { updated, err := srv.Store.Job().UpdateStatusOptimistically(jobId, model.JobStatusPending, model.JobStatusCanceled) if err != nil { - return model.NewAppError("RequestCancellation", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RequestCancellation", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if updated { if srv.metrics != nil { job, err := srv.GetJob(jobId) if err != nil { - return model.NewAppError("RequestCancellation", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RequestCancellation", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } srv.metrics.DecrementJobActive(job.Type) @@ -196,7 +196,7 @@ func (srv *JobServer) RequestCancellation(jobId string) *model.AppError { updated, err = srv.Store.Job().UpdateStatusOptimistically(jobId, model.JobStatusInProgress, model.JobStatusCancelRequested) if err != nil { - return model.NewAppError("RequestCancellation", "app.job.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("RequestCancellation", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if updated { @@ -240,7 +240,7 @@ func GenerateNextStartDateTime(now time.Time, nextStartTime time.Time) *time.Tim func (srv *JobServer) CheckForPendingJobsByType(jobType string) (bool, *model.AppError) { count, err := srv.Store.Job().GetCountByStatusAndType(model.JobStatusPending, jobType) if err != nil { - return false, model.NewAppError("CheckForPendingJobsByType", "app.job.get_count_by_status_and_type.app_error", nil, err.Error(), http.StatusInternalServerError) + return false, model.NewAppError("CheckForPendingJobsByType", "app.job.get_count_by_status_and_type.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return count > 0, nil } @@ -248,7 +248,7 @@ func (srv *JobServer) CheckForPendingJobsByType(jobType string) (bool, *model.Ap func (srv *JobServer) GetJobsByTypeAndStatus(jobType string, status string) ([]*model.Job, *model.AppError) { jobs, err := srv.Store.Job().GetAllByTypeAndStatus(jobType, status) if err != nil { - return nil, model.NewAppError("GetJobsByTypeAndStatus", "app.job.get_all_jobs_by_type_and_status.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetJobsByTypeAndStatus", "app.job.get_all_jobs_by_type_and_status.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return jobs, nil @@ -262,7 +262,7 @@ func (srv *JobServer) GetLastSuccessfulJobByType(jobType string) (*model.Job, *m job, err := srv.Store.Job().GetNewestJobByStatusesAndType(statuses, jobType) var nfErr *store.ErrNotFound if err != nil && !errors.As(err, &nfErr) { - return nil, model.NewAppError("GetLastSuccessfulJobByType", "app.job.get_newest_job_by_status_and_type.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("GetLastSuccessfulJobByType", "app.job.get_newest_job_by_status_and_type.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return job, nil } diff --git a/jobs/migrations/advanced_permissions_phase_2.go b/jobs/migrations/advanced_permissions_phase_2.go index e0c517f0ea..86a2c83a49 100644 --- a/jobs/migrations/advanced_permissions_phase_2.go +++ b/jobs/migrations/advanced_permissions_phase_2.go @@ -81,7 +81,7 @@ func (worker *Worker) runAdvancedPermissionsPhase2Migration(lastDone string) (bo // Run a TeamMembers migration batch. result, err := worker.store.Team().MigrateTeamMembers(progress.LastTeamId, progress.LastUserId) if err != nil { - return false, progress.ToJSON(), model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "app.team.migrate_team_members.update.app_error", nil, err.Error(), http.StatusInternalServerError) + return false, progress.ToJSON(), model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "app.team.migrate_team_members.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if result == nil { // We haven't progressed. That means that we've reached the end of this stage of the migration, and should now advance to the next stage. @@ -96,7 +96,7 @@ func (worker *Worker) runAdvancedPermissionsPhase2Migration(lastDone string) (bo // Run a ChannelMembers migration batch. data, err := worker.store.Channel().MigrateChannelMembers(progress.LastChannelId, progress.LastUserId) if err != nil { - return false, progress.ToJSON(), model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "app.channel.migrate_channel_members.select.app_error", nil, err.Error(), http.StatusInternalServerError) + return false, progress.ToJSON(), model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "app.channel.migrate_channel_members.select.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } if data == nil { // We haven't progressed. That means we've reached the end of this final stage of the migration. diff --git a/jobs/migrations/migrations.go b/jobs/migrations/migrations.go index 7327d953eb..53a8dfdf24 100644 --- a/jobs/migrations/migrations.go +++ b/jobs/migrations/migrations.go @@ -32,7 +32,7 @@ func GetMigrationState(migration string, store store.Store) (string, *model.Job, jobs, err := store.Job().GetAllByType(model.JobTypeMigrations) if err != nil { - return "", nil, model.NewAppError("GetMigrationState", "app.job.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) + return "", nil, model.NewAppError("GetMigrationState", "app.job.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } for _, job := range jobs { diff --git a/jobs/migrations/worker.go b/jobs/migrations/worker.go index 9b121f7865..482709399a 100644 --- a/jobs/migrations/worker.go +++ b/jobs/migrations/worker.go @@ -172,7 +172,7 @@ func (worker *Worker) runMigration(key string, lastDone string) (bool, string, * if done { if nErr := worker.store.System().Save(&model.System{Name: key, Value: "true"}); nErr != nil { - return false, "", model.NewAppError("runMigration", "migrations.system.save.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return false, "", model.NewAppError("runMigration", "migrations.system.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } } diff --git a/jobs/resend_invitation_email/worker.go b/jobs/resend_invitation_email/worker.go index 1cb88238fe..67fd37fa65 100644 --- a/jobs/resend_invitation_email/worker.go +++ b/jobs/resend_invitation_email/worker.go @@ -176,14 +176,14 @@ func (rseworker *ResendInvitationEmailWorker) ResendEmails(job *model.Job, inter emailList, err := rseworker.cleanEmailData(emailListData) if err != nil { - appErr := model.NewAppError("worker: "+rseworker.name, "job_id: "+job.Id, nil, err.Error(), http.StatusInternalServerError) + appErr := model.NewAppError("worker: "+rseworker.name, "job_id: "+job.Id, nil, "", http.StatusInternalServerError).Wrap(err) mlog.Error("Worker: Failed to clean emails string data", mlog.String("worker", rseworker.name), mlog.String("job_id", job.Id), mlog.String("error", appErr.Error())) rseworker.setJobError(job, appErr) } channelList, err := rseworker.cleanChannelsData(channelListData) if err != nil { - appErr := model.NewAppError("worker: "+rseworker.name, "job_id: "+job.Id, nil, err.Error(), http.StatusInternalServerError) + appErr := model.NewAppError("worker: "+rseworker.name, "job_id: "+job.Id, nil, "", http.StatusInternalServerError).Wrap(err) mlog.Error("Worker: Failed to clean channel string data", mlog.String("worker", rseworker.name), mlog.String("job_id", job.Id), mlog.String("error", appErr.Error())) rseworker.setJobError(job, appErr) } diff --git a/manualtesting/manual_testing.go b/manualtesting/manual_testing.go index ae15be9814..5f5381fc99 100644 --- a/manualtesting/manual_testing.go +++ b/manualtesting/manual_testing.go @@ -84,11 +84,11 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) { var appErr *model.AppError switch { case errors.As(err, &invErr): - c.Err = model.NewAppError("manualTest", "app.team.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + c.Err = model.NewAppError("manualTest", "app.team.save.existing.app_error", nil, "", http.StatusBadRequest).Wrap(err) case errors.As(err, &appErr): c.Err = appErr default: - c.Err = model.NewAppError("manualTest", "app.team.save.app_error", nil, err.Error(), http.StatusInternalServerError) + c.Err = model.NewAppError("manualTest", "app.team.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return } @@ -114,7 +114,7 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) { if ok { c.Err = appErr } else { - c.Err = model.NewAppError("manualTest", "app.user.save.app_error", nil, err.Error(), http.StatusInternalServerError) + c.Err = model.NewAppError("manualTest", "app.user.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return @@ -133,7 +133,7 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) { if ok { c.Err = appErr } else { - c.Err = model.NewAppError("manualTest", "api.user.login.bot_login_forbidden.app_error", nil, err.Error(), http.StatusInternalServerError) + c.Err = model.NewAppError("manualTest", "api.user.login.bot_login_forbidden.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return } diff --git a/model/client4.go b/model/client4.go index 0b2fc3a6bd..b217af9b8e 100644 --- a/model/client4.go +++ b/model/client4.go @@ -663,7 +663,7 @@ func (c *Client4) doUploadFile(url string, body io.Reader, contentType string, c var res FileUploadResponse if err := json.NewDecoder(rp.Body).Decode(&res); err != nil { - return nil, nil, NewAppError("doUploadFile", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("doUploadFile", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &res, BuildResponse(rp), nil } @@ -691,7 +691,7 @@ func (c *Client4) DoEmojiUploadFile(url string, data []byte, contentType string) var e Emoji if err := json.NewDecoder(rp.Body).Decode(&e); err != nil { - return nil, nil, NewAppError("DoEmojiUploadFile", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("DoEmojiUploadFile", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &e, BuildResponse(rp), nil } @@ -779,7 +779,7 @@ func (c *Client4) login(m map[string]string) (*User, *Response, error) { var user User if err := json.NewDecoder(r.Body).Decode(&user); err != nil { - return nil, nil, NewAppError("login", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("login", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &user, BuildResponse(r), nil } @@ -925,7 +925,7 @@ func (c *Client4) GetUserByUsername(userName, etag string) (*User, *Response, er return &u, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&u); err != nil { - return nil, nil, NewAppError("GetUserByUsername", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUserByUsername", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &u, BuildResponse(r), nil } @@ -942,7 +942,7 @@ func (c *Client4) GetUserByEmail(email, etag string) (*User, *Response, error) { return &u, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&u); err != nil { - return nil, nil, NewAppError("GetUserByEmail", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUserByEmail", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &u, BuildResponse(r), nil } @@ -960,7 +960,7 @@ func (c *Client4) AutocompleteUsersInTeam(teamId string, username string, limit return &u, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&u); err != nil { - return nil, nil, NewAppError("AutocompleteUsersInTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AutocompleteUsersInTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &u, BuildResponse(r), nil } @@ -978,7 +978,7 @@ func (c *Client4) AutocompleteUsersInChannel(teamId string, channelId string, us return &u, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&u); err != nil { - return nil, nil, NewAppError("AutocompleteUsersInChannel", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AutocompleteUsersInChannel", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &u, BuildResponse(r), nil } @@ -996,7 +996,7 @@ func (c *Client4) AutocompleteUsers(username string, limit int, etag string) (*U return &u, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&u); err != nil { - return nil, nil, NewAppError("AutocompleteUsers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AutocompleteUsers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &u, BuildResponse(r), nil } @@ -1011,7 +1011,7 @@ func (c *Client4) GetDefaultProfileImage(userId string) ([]byte, *Response, erro data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("GetDefaultProfileImage", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("GetDefaultProfileImage", "model.client.read_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil @@ -1027,7 +1027,7 @@ func (c *Client4) GetProfileImage(userId, etag string) ([]byte, *Response, error data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("GetProfileImage", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("GetProfileImage", "model.client.read_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil } @@ -1045,7 +1045,7 @@ func (c *Client4) GetUsers(page int, perPage int, etag string) ([]*User, *Respon return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1063,7 +1063,7 @@ func (c *Client4) GetUsersInTeam(teamId string, page int, perPage int, etag stri return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersInTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersInTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1081,7 +1081,7 @@ func (c *Client4) GetNewUsersInTeam(teamId string, page int, perPage int, etag s return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetNewUsersInTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetNewUsersInTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1099,7 +1099,7 @@ func (c *Client4) GetRecentlyActiveUsersInTeam(teamId string, page int, perPage return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetRecentlyActiveUsersInTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetRecentlyActiveUsersInTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1117,7 +1117,7 @@ func (c *Client4) GetActiveUsersInTeam(teamId string, page int, perPage int, eta return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetActiveUsersInTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetActiveUsersInTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1135,7 +1135,7 @@ func (c *Client4) GetUsersNotInTeam(teamId string, page int, perPage int, etag s return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersNotInTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersNotInTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1153,7 +1153,7 @@ func (c *Client4) GetUsersInChannel(channelId string, page int, perPage int, eta return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersInChannel", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersInChannel", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1171,7 +1171,7 @@ func (c *Client4) GetUsersInChannelByStatus(channelId string, page int, perPage return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersInChannelByStatus", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersInChannelByStatus", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1189,7 +1189,7 @@ func (c *Client4) GetUsersNotInChannel(teamId, channelId string, page int, perPa return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersNotInChannel", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersNotInChannel", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1207,7 +1207,7 @@ func (c *Client4) GetUsersWithoutTeam(page int, perPage int, etag string) ([]*Us return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersWithoutTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersWithoutTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1225,7 +1225,7 @@ func (c *Client4) GetUsersInGroup(groupID string, page int, perPage int, etag st return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersInGroup", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersInGroup", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1239,7 +1239,7 @@ func (c *Client4) GetUsersByIds(userIds []string) ([]*User, *Response, error) { defer closeBody(r) var list []*User if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersByIds", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersByIds", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1263,7 +1263,7 @@ func (c *Client4) GetUsersByIdsWithOptions(userIds []string, options *UserGetByI defer closeBody(r) var list []*User if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersByIdsWithOptions", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersByIdsWithOptions", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1277,7 +1277,7 @@ func (c *Client4) GetUsersByUsernames(usernames []string) ([]*User, *Response, e defer closeBody(r) var list []*User if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersByUsernames", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersByUsernames", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1774,7 +1774,7 @@ func (c *Client4) GetUserAccessTokens(page int, perPage int) ([]*UserAccessToken defer closeBody(r) var list []*UserAccessToken if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUserAccessTokens", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUserAccessTokens", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1791,7 +1791,7 @@ func (c *Client4) GetUserAccessToken(tokenId string) (*UserAccessToken, *Respons defer closeBody(r) var uat UserAccessToken if err := json.NewDecoder(r.Body).Decode(&uat); err != nil { - return nil, nil, NewAppError("GetUserAccessToken", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUserAccessToken", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &uat, BuildResponse(r), nil } @@ -1809,7 +1809,7 @@ func (c *Client4) GetUserAccessTokensForUser(userId string, page, perPage int) ( defer closeBody(r) var list []*UserAccessToken if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUserAccessTokensForUser", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUserAccessTokensForUser", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1831,7 +1831,7 @@ func (c *Client4) RevokeUserAccessToken(tokenId string) (*Response, error) { func (c *Client4) SearchUserAccessTokens(search *UserAccessTokenSearch) ([]*UserAccessToken, *Response, error) { buf, err := json.Marshal(search) if err != nil { - return nil, nil, NewAppError("SearchUserAccessTokens", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchUserAccessTokens", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.usersRoute()+"/tokens/search", buf) if err != nil { @@ -1840,7 +1840,7 @@ func (c *Client4) SearchUserAccessTokens(search *UserAccessTokenSearch) ([]*User defer closeBody(r) var list []*UserAccessToken if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("SearchUserAccessTokens", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchUserAccessTokens", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -1877,7 +1877,7 @@ func (c *Client4) EnableUserAccessToken(tokenId string) (*Response, error) { func (c *Client4) CreateBot(bot *Bot) (*Bot, *Response, error) { buf, err := json.Marshal(bot) if err != nil { - return nil, nil, NewAppError("CreateBot", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateBot", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.botsRoute(), buf) if err != nil { @@ -1888,7 +1888,7 @@ func (c *Client4) CreateBot(bot *Bot) (*Bot, *Response, error) { var resp *Bot err = json.NewDecoder(r.Body).Decode(&resp) if err != nil { - return nil, BuildResponse(r), NewAppError("CreateBot", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("CreateBot", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return resp, BuildResponse(r), nil @@ -1898,7 +1898,7 @@ func (c *Client4) CreateBot(bot *Bot) (*Bot, *Response, error) { func (c *Client4) PatchBot(userId string, patch *BotPatch) (*Bot, *Response, error) { buf, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("PatchBot", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchBot", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.botRoute(userId), buf) if err != nil { @@ -1909,7 +1909,7 @@ func (c *Client4) PatchBot(userId string, patch *BotPatch) (*Bot, *Response, err var bot *Bot err = json.NewDecoder(r.Body).Decode(&bot) if err != nil { - return nil, BuildResponse(r), NewAppError("PatchBot", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("PatchBot", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bot, BuildResponse(r), nil @@ -1926,7 +1926,7 @@ func (c *Client4) GetBot(userId string, etag string) (*Bot, *Response, error) { var bot *Bot err = json.NewDecoder(r.Body).Decode(&bot) if err != nil { - return nil, BuildResponse(r), NewAppError("GetBot", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetBot", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bot, BuildResponse(r), nil @@ -1943,7 +1943,7 @@ func (c *Client4) GetBotIncludeDeleted(userId string, etag string) (*Bot, *Respo var bot *Bot err = json.NewDecoder(r.Body).Decode(&bot) if err != nil { - return nil, BuildResponse(r), NewAppError("GetBotIncludeDeleted", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetBotIncludeDeleted", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bot, BuildResponse(r), nil @@ -1961,7 +1961,7 @@ func (c *Client4) GetBots(page, perPage int, etag string) ([]*Bot, *Response, er var bots BotList err = json.NewDecoder(r.Body).Decode(&bots) if err != nil { - return nil, BuildResponse(r), NewAppError("GetBots", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetBots", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bots, BuildResponse(r), nil } @@ -1978,7 +1978,7 @@ func (c *Client4) GetBotsIncludeDeleted(page, perPage int, etag string) ([]*Bot, var bots BotList err = json.NewDecoder(r.Body).Decode(&bots) if err != nil { - return nil, BuildResponse(r), NewAppError("GetBotsIncludeDeleted", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetBotsIncludeDeleted", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bots, BuildResponse(r), nil } @@ -1995,7 +1995,7 @@ func (c *Client4) GetBotsOrphaned(page, perPage int, etag string) ([]*Bot, *Resp var bots BotList err = json.NewDecoder(r.Body).Decode(&bots) if err != nil { - return nil, BuildResponse(r), NewAppError("GetBotsOrphaned", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetBotsOrphaned", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bots, BuildResponse(r), nil } @@ -2011,7 +2011,7 @@ func (c *Client4) DisableBot(botUserId string) (*Bot, *Response, error) { var bot *Bot err = json.NewDecoder(r.Body).Decode(&bot) if err != nil { - return nil, BuildResponse(r), NewAppError("DisableBot", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("DisableBot", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bot, BuildResponse(r), nil @@ -2028,7 +2028,7 @@ func (c *Client4) EnableBot(botUserId string) (*Bot, *Response, error) { var bot *Bot err = json.NewDecoder(r.Body).Decode(&bot) if err != nil { - return nil, BuildResponse(r), NewAppError("EnableBot", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("EnableBot", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bot, BuildResponse(r), nil @@ -2045,7 +2045,7 @@ func (c *Client4) AssignBot(botUserId, newOwnerId string) (*Bot, *Response, erro var bot *Bot err = json.NewDecoder(r.Body).Decode(&bot) if err != nil { - return nil, BuildResponse(r), NewAppError("AssignBot", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("AssignBot", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return bot, BuildResponse(r), nil @@ -2057,7 +2057,7 @@ func (c *Client4) AssignBot(botUserId, newOwnerId string) (*Bot, *Response, erro func (c *Client4) CreateTeam(team *Team) (*Team, *Response, error) { buf, err := json.Marshal(team) if err != nil { - return nil, nil, NewAppError("CreateTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.teamsRoute(), buf) if err != nil { @@ -2066,7 +2066,7 @@ func (c *Client4) CreateTeam(team *Team) (*Team, *Response, error) { defer closeBody(r) var t Team if err := json.NewDecoder(r.Body).Decode(&t); err != nil { - return nil, nil, NewAppError("CreateTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &t, BuildResponse(r), nil } @@ -2080,7 +2080,7 @@ func (c *Client4) GetTeam(teamId, etag string) (*Team, *Response, error) { defer closeBody(r) var t Team if err := json.NewDecoder(r.Body).Decode(&t); err != nil { - return nil, nil, NewAppError("GetTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &t, BuildResponse(r), nil } @@ -2095,7 +2095,7 @@ func (c *Client4) GetAllTeams(etag string, page int, perPage int) ([]*Team, *Res defer closeBody(r) var list []*Team if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetAllTeams", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetAllTeams", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -2110,7 +2110,7 @@ func (c *Client4) GetAllTeamsWithTotalCount(etag string, page int, perPage int) defer closeBody(r) var listWithCount TeamsWithCount if err := json.NewDecoder(r.Body).Decode(&listWithCount); err != nil { - return nil, 0, nil, NewAppError("GetAllTeamsWithTotalCount", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, nil, NewAppError("GetAllTeamsWithTotalCount", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return listWithCount.Teams, listWithCount.TotalCount, BuildResponse(r), nil } @@ -2126,7 +2126,7 @@ func (c *Client4) GetAllTeamsExcludePolicyConstrained(etag string, page int, per defer closeBody(r) var list []*Team if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetAllTeamsExcludePolicyConstrained", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetAllTeamsExcludePolicyConstrained", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -2140,7 +2140,7 @@ func (c *Client4) GetTeamByName(name, etag string) (*Team, *Response, error) { defer closeBody(r) var t Team if err := json.NewDecoder(r.Body).Decode(&t); err != nil { - return nil, nil, NewAppError("GetTeamByName", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamByName", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &t, BuildResponse(r), nil } @@ -2149,7 +2149,7 @@ func (c *Client4) GetTeamByName(name, etag string) (*Team, *Response, error) { func (c *Client4) SearchTeams(search *TeamSearch) ([]*Team, *Response, error) { buf, err := json.Marshal(search) if err != nil { - return nil, nil, NewAppError("SearchTeams", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchTeams", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.teamsRoute()+"/search", buf) if err != nil { @@ -2158,7 +2158,7 @@ func (c *Client4) SearchTeams(search *TeamSearch) ([]*Team, *Response, error) { defer closeBody(r) var list []*Team if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("SearchTeams", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchTeams", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -2173,7 +2173,7 @@ func (c *Client4) SearchTeamsPaged(search *TeamSearch) ([]*Team, int64, *Respons } buf, err := json.Marshal(search) if err != nil { - return nil, 0, BuildResponse(nil), NewAppError("SearchTeamsPaged", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, BuildResponse(nil), NewAppError("SearchTeamsPaged", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.teamsRoute()+"/search", buf) if err != nil { @@ -2182,7 +2182,7 @@ func (c *Client4) SearchTeamsPaged(search *TeamSearch) ([]*Team, int64, *Respons defer closeBody(r) var listWithCount TeamsWithCount if err := json.NewDecoder(r.Body).Decode(&listWithCount); err != nil { - return nil, 0, nil, NewAppError("GetAllTeamsWithTotalCount", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, nil, NewAppError("GetAllTeamsWithTotalCount", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return listWithCount.Teams, listWithCount.TotalCount, BuildResponse(r), nil } @@ -2207,7 +2207,7 @@ func (c *Client4) GetTeamsForUser(userId, etag string) ([]*Team, *Response, erro defer closeBody(r) var list []*Team if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetTeamsForUser", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamsForUser", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -2224,7 +2224,7 @@ func (c *Client4) GetTeamMember(teamId, userId, etag string) (*TeamMember, *Resp return &tm, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&tm); err != nil { - return nil, nil, NewAppError("GetTeamMember", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamMember", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &tm, BuildResponse(r), nil } @@ -2244,7 +2244,7 @@ func (c *Client4) UpdateTeamMemberRoles(teamId, userId, newRoles string) (*Respo func (c *Client4) UpdateTeamMemberSchemeRoles(teamId string, userId string, schemeRoles *SchemeRoles) (*Response, error) { buf, err := json.Marshal(schemeRoles) if err != nil { - return nil, NewAppError("UpdateTeamMemberSchemeRoles", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("UpdateTeamMemberSchemeRoles", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.teamMemberRoute(teamId, userId)+"/schemeRoles", buf) if err != nil { @@ -2258,7 +2258,7 @@ func (c *Client4) UpdateTeamMemberSchemeRoles(teamId string, userId string, sche func (c *Client4) UpdateTeam(team *Team) (*Team, *Response, error) { buf, err := json.Marshal(team) if err != nil { - return nil, nil, NewAppError("UpdateTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.teamRoute(team.Id), buf) if err != nil { @@ -2267,7 +2267,7 @@ func (c *Client4) UpdateTeam(team *Team) (*Team, *Response, error) { defer closeBody(r) var t Team if err := json.NewDecoder(r.Body).Decode(&t); err != nil { - return nil, nil, NewAppError("UpdateTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &t, BuildResponse(r), nil } @@ -2276,7 +2276,7 @@ func (c *Client4) UpdateTeam(team *Team) (*Team, *Response, error) { func (c *Client4) PatchTeam(teamId string, patch *TeamPatch) (*Team, *Response, error) { buf, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("PatchTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.teamRoute(teamId)+"/patch", buf) if err != nil { @@ -2285,7 +2285,7 @@ func (c *Client4) PatchTeam(teamId string, patch *TeamPatch) (*Team, *Response, defer closeBody(r) var t Team if err := json.NewDecoder(r.Body).Decode(&t); err != nil { - return nil, nil, NewAppError("PatchTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &t, BuildResponse(r), nil } @@ -2299,7 +2299,7 @@ func (c *Client4) RestoreTeam(teamId string) (*Team, *Response, error) { defer closeBody(r) var t Team if err := json.NewDecoder(r.Body).Decode(&t); err != nil { - return nil, nil, NewAppError("RestoreTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("RestoreTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &t, BuildResponse(r), nil } @@ -2313,7 +2313,7 @@ func (c *Client4) RegenerateTeamInviteId(teamId string) (*Team, *Response, error defer closeBody(r) var t Team if err := json.NewDecoder(r.Body).Decode(&t); err != nil { - return nil, nil, NewAppError("RegenerateTeamInviteId", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("RegenerateTeamInviteId", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &t, BuildResponse(r), nil } @@ -2350,7 +2350,7 @@ func (c *Client4) UpdateTeamPrivacy(teamId string, privacy string) (*Team, *Resp defer closeBody(r) var t Team if err := json.NewDecoder(r.Body).Decode(&t); err != nil { - return nil, nil, NewAppError("UpdateTeamPrivacy", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateTeamPrivacy", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &t, BuildResponse(r), nil } @@ -2368,7 +2368,7 @@ func (c *Client4) GetTeamMembers(teamId string, page int, perPage int, etag stri return tms, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&tms); err != nil { - return nil, nil, NewAppError("GetTeamMembers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamMembers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return tms, BuildResponse(r), nil } @@ -2387,7 +2387,7 @@ func (c *Client4) GetTeamMembersSortAndWithoutDeletedUsers(teamId string, page i return tms, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&tms); err != nil { - return nil, nil, NewAppError("GetTeamMembersSortAndWithoutDeletedUsers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamMembersSortAndWithoutDeletedUsers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return tms, BuildResponse(r), nil } @@ -2404,7 +2404,7 @@ func (c *Client4) GetTeamMembersForUser(userId string, etag string) ([]*TeamMemb return tms, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&tms); err != nil { - return nil, nil, NewAppError("GetTeamMembersForUser", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamMembersForUser", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return tms, BuildResponse(r), nil } @@ -2419,7 +2419,7 @@ func (c *Client4) GetTeamMembersByIds(teamId string, userIds []string) ([]*TeamM defer closeBody(r) var tms []*TeamMember if err := json.NewDecoder(r.Body).Decode(&tms); err != nil { - return nil, nil, NewAppError("GetTeamMembersByIds", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamMembersByIds", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return tms, BuildResponse(r), nil } @@ -2429,7 +2429,7 @@ func (c *Client4) AddTeamMember(teamId, userId string) (*TeamMember, *Response, member := &TeamMember{TeamId: teamId, UserId: userId} buf, err := json.Marshal(member) if err != nil { - return nil, nil, NewAppError("AddTeamMember", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AddTeamMember", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.teamMembersRoute(teamId), buf) if err != nil { @@ -2438,7 +2438,7 @@ func (c *Client4) AddTeamMember(teamId, userId string) (*TeamMember, *Response, defer closeBody(r) var tm TeamMember if err := json.NewDecoder(r.Body).Decode(&tm); err != nil { - return nil, nil, NewAppError("AddTeamMember", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AddTeamMember", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &tm, BuildResponse(r), nil } @@ -2463,7 +2463,7 @@ func (c *Client4) AddTeamMemberFromInvite(token, inviteId string) (*TeamMember, defer closeBody(r) var tm TeamMember if err := json.NewDecoder(r.Body).Decode(&tm); err != nil { - return nil, nil, NewAppError("AddTeamMemberFromInvite", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AddTeamMemberFromInvite", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &tm, BuildResponse(r), nil } @@ -2477,7 +2477,7 @@ func (c *Client4) AddTeamMembers(teamId string, userIds []string) ([]*TeamMember } js, err := json.Marshal(members) if err != nil { - return nil, nil, NewAppError("AddTeamMembers", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AddTeamMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.teamMembersRoute(teamId)+"/batch", string(js)) if err != nil { @@ -2486,7 +2486,7 @@ func (c *Client4) AddTeamMembers(teamId string, userIds []string) ([]*TeamMember defer closeBody(r) var tms []*TeamMember if err := json.NewDecoder(r.Body).Decode(&tms); err != nil { - return nil, nil, NewAppError("AddTeamMembers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AddTeamMembers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return tms, BuildResponse(r), nil } @@ -2500,7 +2500,7 @@ func (c *Client4) AddTeamMembersGracefully(teamId string, userIds []string) ([]* } js, err := json.Marshal(members) if err != nil { - return nil, nil, NewAppError("AddTeamMembersGracefully", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AddTeamMembersGracefully", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.teamMembersRoute(teamId)+"/batch?graceful="+c.boolString(true), string(js)) @@ -2510,7 +2510,7 @@ func (c *Client4) AddTeamMembersGracefully(teamId string, userIds []string) ([]* defer closeBody(r) var tms []*TeamMemberWithError if err := json.NewDecoder(r.Body).Decode(&tms); err != nil { - return nil, nil, NewAppError("AddTeamMembersGracefully", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AddTeamMembersGracefully", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return tms, BuildResponse(r), nil } @@ -2535,7 +2535,7 @@ func (c *Client4) GetTeamStats(teamId, etag string) (*TeamStats, *Response, erro defer closeBody(r) var ts TeamStats if err := json.NewDecoder(r.Body).Decode(&ts); err != nil { - return nil, nil, NewAppError("GetTeamStats", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamStats", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &ts, BuildResponse(r), nil } @@ -2550,7 +2550,7 @@ func (c *Client4) GetTotalUsersStats(etag string) (*UsersStats, *Response, error defer closeBody(r) var stats UsersStats if err := json.NewDecoder(r.Body).Decode(&stats); err != nil { - return nil, nil, NewAppError("GetTotalUsersStats", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTotalUsersStats", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &stats, BuildResponse(r), nil } @@ -2566,7 +2566,7 @@ func (c *Client4) GetTeamUnread(teamId, userId string) (*TeamUnread, *Response, defer closeBody(r) var tu TeamUnread if err := json.NewDecoder(r.Body).Decode(&tu); err != nil { - return nil, nil, NewAppError("GetTeamUnread", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamUnread", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &tu, BuildResponse(r), nil } @@ -2629,7 +2629,7 @@ func (c *Client4) InviteGuestsToTeam(teamId string, userEmails []string, channel } buf, err := json.Marshal(guestsInvite) if err != nil { - return nil, NewAppError("InviteGuestsToTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("InviteGuestsToTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.teamRoute(teamId)+"/invite-guests/email", buf) if err != nil { @@ -2649,7 +2649,7 @@ func (c *Client4) InviteUsersToTeamGracefully(teamId string, userEmails []string defer closeBody(r) var list []*EmailInviteWithError if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("InviteUsersToTeamGracefully", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("InviteUsersToTeamGracefully", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -2663,7 +2663,7 @@ func (c *Client4) InviteUsersToTeamAndChannelsGracefully(teamId string, userEmai } buf, err := json.Marshal(memberInvite) if err != nil { - return nil, nil, NewAppError("InviteMembersToTeamAndChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("InviteMembersToTeamAndChannels", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.teamRoute(teamId)+"/invite/email?graceful="+c.boolString(true), buf) if err != nil { @@ -2672,7 +2672,7 @@ func (c *Client4) InviteUsersToTeamAndChannelsGracefully(teamId string, userEmai defer closeBody(r) var list []*EmailInviteWithError if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("InviteUsersToTeamGracefully", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("InviteUsersToTeamGracefully", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -2686,7 +2686,7 @@ func (c *Client4) InviteGuestsToTeamGracefully(teamId string, userEmails []strin } buf, err := json.Marshal(guestsInvite) if err != nil { - return nil, nil, NewAppError("InviteGuestsToTeamGracefully", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("InviteGuestsToTeamGracefully", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.teamRoute(teamId)+"/invite-guests/email?graceful="+c.boolString(true), buf) if err != nil { @@ -2695,7 +2695,7 @@ func (c *Client4) InviteGuestsToTeamGracefully(teamId string, userEmails []strin defer closeBody(r) var list []*EmailInviteWithError if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("InviteGuestsToTeamGracefully", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("InviteGuestsToTeamGracefully", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -2719,7 +2719,7 @@ func (c *Client4) GetTeamInviteInfo(inviteId string) (*Team, *Response, error) { defer closeBody(r) var t Team if err := json.NewDecoder(r.Body).Decode(&t); err != nil { - return nil, nil, NewAppError("GetTeamInviteInfo", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamInviteInfo", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &t, BuildResponse(r), nil } @@ -2731,15 +2731,15 @@ func (c *Client4) SetTeamIcon(teamId string, data []byte) (*Response, error) { part, err := writer.CreateFormFile("image", "teamIcon.png") if err != nil { - return nil, NewAppError("SetTeamIcon", "model.client.set_team_icon.no_file.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("SetTeamIcon", "model.client.set_team_icon.no_file.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if _, err = io.Copy(part, bytes.NewBuffer(data)); err != nil { - return nil, NewAppError("SetTeamIcon", "model.client.set_team_icon.no_file.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("SetTeamIcon", "model.client.set_team_icon.no_file.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if err = writer.Close(); err != nil { - return nil, NewAppError("SetTeamIcon", "model.client.set_team_icon.writer.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("SetTeamIcon", "model.client.set_team_icon.writer.app_error", nil, "", http.StatusBadRequest).Wrap(err) } rq, err := http.NewRequest("POST", c.APIURL+c.teamRoute(teamId)+"/image", bytes.NewReader(body.Bytes())) @@ -2775,7 +2775,7 @@ func (c *Client4) GetTeamIcon(teamId, etag string) ([]byte, *Response, error) { data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("GetTeamIcon", "model.client.get_team_icon.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("GetTeamIcon", "model.client.get_team_icon.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil } @@ -2820,7 +2820,7 @@ func (c *Client4) getAllChannels(page int, perPage int, etag string, opts Channe var ch ChannelListWithTeamData err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("getAllChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("getAllChannels", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -2837,7 +2837,7 @@ func (c *Client4) GetAllChannelsWithCount(page int, perPage int, etag string) (C var cwc *ChannelsWithCount err = json.NewDecoder(r.Body).Decode(&cwc) if err != nil { - return nil, 0, BuildResponse(r), NewAppError("GetAllChannelsWithCount", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, BuildResponse(r), NewAppError("GetAllChannelsWithCount", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return cwc.Channels, cwc.TotalCount, BuildResponse(r), nil } @@ -2846,7 +2846,7 @@ func (c *Client4) GetAllChannelsWithCount(page int, perPage int, etag string) (C func (c *Client4) CreateChannel(channel *Channel) (*Channel, *Response, error) { channelJSON, err := json.Marshal(channel) if err != nil { - return nil, nil, NewAppError("CreateChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.channelsRoute(), string(channelJSON)) if err != nil { @@ -2857,7 +2857,7 @@ func (c *Client4) CreateChannel(channel *Channel) (*Channel, *Response, error) { var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("CreateChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("CreateChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -2866,7 +2866,7 @@ func (c *Client4) CreateChannel(channel *Channel) (*Channel, *Response, error) { func (c *Client4) UpdateChannel(channel *Channel) (*Channel, *Response, error) { channelJSON, err := json.Marshal(channel) if err != nil { - return nil, nil, NewAppError("UpdateChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPut(c.channelRoute(channel.Id), string(channelJSON)) if err != nil { @@ -2877,7 +2877,7 @@ func (c *Client4) UpdateChannel(channel *Channel) (*Channel, *Response, error) { var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("UpdateChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("UpdateChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -2886,7 +2886,7 @@ func (c *Client4) UpdateChannel(channel *Channel) (*Channel, *Response, error) { func (c *Client4) PatchChannel(channelId string, patch *ChannelPatch) (*Channel, *Response, error) { buf, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("PatchChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.channelRoute(channelId)+"/patch", buf) if err != nil { @@ -2897,7 +2897,7 @@ func (c *Client4) PatchChannel(channelId string, patch *ChannelPatch) (*Channel, var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("PatchChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("PatchChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -2914,7 +2914,7 @@ func (c *Client4) UpdateChannelPrivacy(channelId string, privacy ChannelType) (* var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("UpdateChannelPrivacy", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("UpdateChannelPrivacy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -2930,7 +2930,7 @@ func (c *Client4) RestoreChannel(channelId string) (*Channel, *Response, error) var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("RestoreChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("RestoreChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -2948,7 +2948,7 @@ func (c *Client4) CreateDirectChannel(userId1, userId2 string) (*Channel, *Respo var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("CreateDirectChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("CreateDirectChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -2964,7 +2964,7 @@ func (c *Client4) CreateGroupChannel(userIds []string) (*Channel, *Response, err var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("CreateGroupChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("CreateGroupChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -2980,7 +2980,7 @@ func (c *Client4) GetChannel(channelId, etag string) (*Channel, *Response, error var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -2994,7 +2994,7 @@ func (c *Client4) GetChannelStats(channelId string, etag string) (*ChannelStats, defer closeBody(r) var stats ChannelStats if err := json.NewDecoder(r.Body).Decode(&stats); err != nil { - return nil, nil, NewAppError("GetChannelStats", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetChannelStats", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &stats, BuildResponse(r), nil } @@ -3023,7 +3023,7 @@ func (c *Client4) GetPinnedPosts(channelId string, etag string) (*PostList, *Res } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetPinnedPosts", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPinnedPosts", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -3040,7 +3040,7 @@ func (c *Client4) GetPrivateChannelsForTeam(teamId string, page int, perPage int var ch []*Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetPrivateChannelsForTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetPrivateChannelsForTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3057,7 +3057,7 @@ func (c *Client4) GetPublicChannelsForTeam(teamId string, page int, perPage int, var ch []*Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetPublicChannelsForTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetPublicChannelsForTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3074,7 +3074,7 @@ func (c *Client4) GetDeletedChannelsForTeam(teamId string, page int, perPage int var ch []*Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetDeletedChannelsForTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetDeletedChannelsForTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3090,7 +3090,7 @@ func (c *Client4) GetPublicChannelsByIdsForTeam(teamId string, channelIds []stri var ch []*Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetPublicChannelsByIdsForTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetPublicChannelsByIdsForTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3106,7 +3106,7 @@ func (c *Client4) GetChannelsForTeamForUser(teamId, userId string, includeDelete var ch []*Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelsForTeamForUser", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelsForTeamForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3124,7 +3124,7 @@ func (c *Client4) GetChannelsForTeamAndUserWithLastDeleteAt(teamId, userId strin var ch []*Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelsForTeamAndUserWithLastDeleteAt", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelsForTeamAndUserWithLastDeleteAt", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3142,7 +3142,7 @@ func (c *Client4) GetChannelsForUserWithLastDeleteAt(userID string, lastDeleteAt var ch []*Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelsForUserWithLastDeleteAt", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelsForUserWithLastDeleteAt", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3151,7 +3151,7 @@ func (c *Client4) GetChannelsForUserWithLastDeleteAt(userID string, lastDeleteAt func (c *Client4) SearchChannels(teamId string, search *ChannelSearch) ([]*Channel, *Response, error) { searchJSON, err := json.Marshal(search) if err != nil { - return nil, nil, NewAppError("SearchChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchChannels", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.channelsForTeamRoute(teamId)+"/search", string(searchJSON)) if err != nil { @@ -3162,7 +3162,7 @@ func (c *Client4) SearchChannels(teamId string, search *ChannelSearch) ([]*Chann var ch []*Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("SearchChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("SearchChannels", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3171,7 +3171,7 @@ func (c *Client4) SearchChannels(teamId string, search *ChannelSearch) ([]*Chann func (c *Client4) SearchArchivedChannels(teamId string, search *ChannelSearch) ([]*Channel, *Response, error) { searchJSON, err := json.Marshal(search) if err != nil { - return nil, nil, NewAppError("SearchArchivedChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchArchivedChannels", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.channelsForTeamRoute(teamId)+"/search_archived", string(searchJSON)) if err != nil { @@ -3182,7 +3182,7 @@ func (c *Client4) SearchArchivedChannels(teamId string, search *ChannelSearch) ( var ch []*Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("SearchArchivedChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("SearchArchivedChannels", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3191,7 +3191,7 @@ func (c *Client4) SearchArchivedChannels(teamId string, search *ChannelSearch) ( func (c *Client4) SearchAllChannels(search *ChannelSearch) (ChannelListWithTeamData, *Response, error) { searchJSON, err := json.Marshal(search) if err != nil { - return nil, nil, NewAppError("SearchAllChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchAllChannels", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.channelsRoute()+"/search", string(searchJSON)) if err != nil { @@ -3202,7 +3202,7 @@ func (c *Client4) SearchAllChannels(search *ChannelSearch) (ChannelListWithTeamD var ch ChannelListWithTeamData err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("SearchAllChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("SearchAllChannels", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3214,7 +3214,7 @@ func (c *Client4) SearchAllChannelsForUser(term string) (ChannelListWithTeamData } searchJSON, err := json.Marshal(search) if err != nil { - return nil, nil, NewAppError("SearchAllChannelsForUser", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchAllChannelsForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.channelsRoute()+"/search?system_console=false", string(searchJSON)) if err != nil { @@ -3225,7 +3225,7 @@ func (c *Client4) SearchAllChannelsForUser(term string) (ChannelListWithTeamData var ch ChannelListWithTeamData err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("SearchAllChannelsForUser", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("SearchAllChannelsForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3234,7 +3234,7 @@ func (c *Client4) SearchAllChannelsForUser(term string) (ChannelListWithTeamData func (c *Client4) SearchAllChannelsPaged(search *ChannelSearch) (*ChannelsWithCount, *Response, error) { searchJSON, err := json.Marshal(search) if err != nil { - return nil, nil, NewAppError("SearchAllChannelsPaged", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchAllChannelsPaged", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.channelsRoute()+"/search", string(searchJSON)) if err != nil { @@ -3245,7 +3245,7 @@ func (c *Client4) SearchAllChannelsPaged(search *ChannelSearch) (*ChannelsWithCo var cwc *ChannelsWithCount err = json.NewDecoder(r.Body).Decode(&cwc) if err != nil { - return nil, BuildResponse(r), NewAppError("GetAllChannelsWithCount", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetAllChannelsWithCount", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return cwc, BuildResponse(r), nil } @@ -3254,7 +3254,7 @@ func (c *Client4) SearchAllChannelsPaged(search *ChannelSearch) (*ChannelsWithCo func (c *Client4) SearchGroupChannels(search *ChannelSearch) ([]*Channel, *Response, error) { searchJSON, err := json.Marshal(search) if err != nil { - return nil, nil, NewAppError("SearchGroupChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchGroupChannels", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.channelsRoute()+"/group/search", string(searchJSON)) if err != nil { @@ -3265,7 +3265,7 @@ func (c *Client4) SearchGroupChannels(search *ChannelSearch) ([]*Channel, *Respo var ch []*Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("SearchGroupChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("SearchGroupChannels", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3305,7 +3305,7 @@ func (c *Client4) MoveChannel(channelId, teamId string, force bool) (*Channel, * var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("MoveChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("MoveChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3321,7 +3321,7 @@ func (c *Client4) GetChannelByName(channelName, teamId string, etag string) (*Ch var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelByName", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelByName", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3337,7 +3337,7 @@ func (c *Client4) GetChannelByNameIncludeDeleted(channelName, teamId string, eta var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelByNameIncludeDeleted", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelByNameIncludeDeleted", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3353,7 +3353,7 @@ func (c *Client4) GetChannelByNameForTeamName(channelName, teamName string, etag var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelByNameForTeamName", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelByNameForTeamName", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3369,7 +3369,7 @@ func (c *Client4) GetChannelByNameForTeamNameIncludeDeleted(channelName, teamNam var ch *Channel err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelByNameForTeamNameIncludeDeleted", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelByNameForTeamNameIncludeDeleted", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3386,7 +3386,7 @@ func (c *Client4) GetChannelMembers(channelId string, page, perPage int, etag st var ch ChannelMembers err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelMembers", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3403,7 +3403,7 @@ func (c *Client4) GetChannelMembersWithTeamData(userID string, page, perPage int var ch ChannelMembersWithTeamData err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelMembersWithTeamData", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelMembersWithTeamData", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3419,7 +3419,7 @@ func (c *Client4) GetChannelMembersByIds(channelId string, userIds []string) (Ch var ch ChannelMembers err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelMembersByIds", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelMembersByIds", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3435,7 +3435,7 @@ func (c *Client4) GetChannelMember(channelId, userId, etag string) (*ChannelMemb var ch *ChannelMember err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelMember", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelMember", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3451,7 +3451,7 @@ func (c *Client4) GetChannelMembersForUser(userId, teamId, etag string) (Channel var ch ChannelMembers err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelMembersForUser", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelMembersForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3461,7 +3461,7 @@ func (c *Client4) ViewChannel(userId string, view *ChannelView) (*ChannelViewRes url := fmt.Sprintf(c.channelsRoute()+"/members/%v/view", userId) buf, err := json.Marshal(view) if err != nil { - return nil, nil, NewAppError("ViewChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("ViewChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(url, buf) if err != nil { @@ -3472,7 +3472,7 @@ func (c *Client4) ViewChannel(userId string, view *ChannelView) (*ChannelViewRes var ch *ChannelViewResponse err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("ViewChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("ViewChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3489,7 +3489,7 @@ func (c *Client4) GetChannelUnread(channelId, userId string) (*ChannelUnread, *R var ch *ChannelUnread err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelUnread", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelUnread", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3509,7 +3509,7 @@ func (c *Client4) UpdateChannelRoles(channelId, userId, roles string) (*Response func (c *Client4) UpdateChannelMemberSchemeRoles(channelId string, userId string, schemeRoles *SchemeRoles) (*Response, error) { buf, err := json.Marshal(schemeRoles) if err != nil { - return nil, NewAppError("UpdateChannelMemberSchemeRoles", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("UpdateChannelMemberSchemeRoles", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.channelMemberRoute(channelId, userId)+"/schemeRoles", buf) if err != nil { @@ -3541,7 +3541,7 @@ func (c *Client4) AddChannelMember(channelId, userId string) (*ChannelMember, *R var ch *ChannelMember err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("AddChannelMember", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("AddChannelMember", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3558,7 +3558,7 @@ func (c *Client4) AddChannelMemberWithRootId(channelId, userId, postRootId strin var ch *ChannelMember err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("AddChannelMemberWithRootId", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("AddChannelMemberWithRootId", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3585,7 +3585,7 @@ func (c *Client4) AutocompleteChannelsForTeam(teamId, name string) (ChannelList, var ch ChannelList err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("AutocompleteChannelsForTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("AutocompleteChannelsForTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3602,7 +3602,7 @@ func (c *Client4) AutocompleteChannelsForTeamForSearch(teamId, name string) (Cha var ch ChannelList err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("AutocompleteChannelsForTeamForSearch", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("AutocompleteChannelsForTeamForSearch", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -3617,7 +3617,7 @@ func (c *Client4) GetTopChannelsForTeamSince(teamId string, timeRange string, pa defer closeBody(r) var topChannels *TopChannelList if err := json.NewDecoder(r.Body).Decode(&topChannels); err != nil { - return nil, nil, NewAppError("GetTopChannelsForTeamSince", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTopChannelsForTeamSince", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topChannels, BuildResponse(r), nil } @@ -3637,7 +3637,7 @@ func (c *Client4) GetTopChannelsForUserSince(teamId string, timeRange string, pa defer closeBody(r) var topChannels *TopChannelList if err := json.NewDecoder(r.Body).Decode(&topChannels); err != nil { - return nil, nil, NewAppError("GetTopChannelsForUserSince", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTopChannelsForUserSince", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topChannels, BuildResponse(r), nil } @@ -3648,7 +3648,7 @@ func (c *Client4) GetTopChannelsForUserSince(teamId string, timeRange string, pa func (c *Client4) CreatePost(post *Post) (*Post, *Response, error) { postJSON, err := json.Marshal(post) if err != nil { - return nil, nil, NewAppError("CreatePost", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreatePost", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.postsRoute(), string(postJSON)) if err != nil { @@ -3660,7 +3660,7 @@ func (c *Client4) CreatePost(post *Post) (*Post, *Response, error) { return &p, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("CreatePost", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreatePost", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -3669,7 +3669,7 @@ func (c *Client4) CreatePost(post *Post) (*Post, *Response, error) { func (c *Client4) CreatePostEphemeral(post *PostEphemeral) (*Post, *Response, error) { postJSON, err := json.Marshal(post) if err != nil { - return nil, nil, NewAppError("CreatePostEphemeral", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreatePostEphemeral", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.postsEphemeralRoute(), string(postJSON)) if err != nil { @@ -3681,7 +3681,7 @@ func (c *Client4) CreatePostEphemeral(post *PostEphemeral) (*Post, *Response, er return &p, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("CreatePostEphemeral", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreatePostEphemeral", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -3690,7 +3690,7 @@ func (c *Client4) CreatePostEphemeral(post *PostEphemeral) (*Post, *Response, er func (c *Client4) UpdatePost(postId string, post *Post) (*Post, *Response, error) { postJSON, err := json.Marshal(post) if err != nil { - return nil, nil, NewAppError("UpdatePost", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdatePost", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPut(c.postRoute(postId), string(postJSON)) if err != nil { @@ -3702,7 +3702,7 @@ func (c *Client4) UpdatePost(postId string, post *Post) (*Post, *Response, error return &p, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("UpdatePost", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdatePost", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -3711,7 +3711,7 @@ func (c *Client4) UpdatePost(postId string, post *Post) (*Post, *Response, error func (c *Client4) PatchPost(postId string, patch *PostPatch) (*Post, *Response, error) { buf, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("PatchPost", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchPost", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.postRoute(postId)+"/patch", buf) if err != nil { @@ -3723,7 +3723,7 @@ func (c *Client4) PatchPost(postId string, patch *PostPatch) (*Post, *Response, return &p, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("PatchPost", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchPost", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -3732,7 +3732,7 @@ func (c *Client4) PatchPost(postId string, patch *PostPatch) (*Post, *Response, func (c *Client4) SetPostUnread(userId string, postId string, collapsedThreadsSupported bool) (*Response, error) { b, err := json.Marshal(map[string]bool{"collapsed_threads_supported": collapsedThreadsSupported}) if err != nil { - return nil, NewAppError("SetPostUnread", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("SetPostUnread", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.userRoute(userId)+c.postRoute(postId)+"/set_unread", b) if err != nil { @@ -3748,7 +3748,7 @@ func (c *Client4) SetPostUnread(userId string, postId string, collapsedThreadsSu func (c *Client4) SetPostReminder(reminder *PostReminder) (*Response, error) { b, err := json.Marshal(reminder) if err != nil { - return nil, NewAppError("SetPostReminder", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("SetPostReminder", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.userRoute(reminder.UserId)+c.postRoute(reminder.PostId)+"/reminder", b) @@ -3792,7 +3792,7 @@ func (c *Client4) GetPost(postId string, etag string) (*Post, *Response, error) return &post, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&post); err != nil { - return nil, nil, NewAppError("GetPost", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPost", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &post, BuildResponse(r), nil } @@ -3810,7 +3810,7 @@ func (c *Client4) GetPostIncludeDeleted(postId string, etag string) (*Post, *Res return &post, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&post); err != nil { - return nil, nil, NewAppError("GetPostIncludeDeleted", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPostIncludeDeleted", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &post, BuildResponse(r), nil } @@ -3841,7 +3841,7 @@ func (c *Client4) GetPostThread(postId string, etag string, collapsedThreads boo return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetPostThread", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPostThread", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -3884,7 +3884,7 @@ func (c *Client4) GetPostThreadWithOpts(postID string, etag string, opts GetPost return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetPostThread", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPostThread", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -3905,7 +3905,7 @@ func (c *Client4) GetPostsForChannel(channelId string, page, perPage int, etag s return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetPostsForChannel", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPostsForChannel", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -3914,7 +3914,7 @@ func (c *Client4) GetPostsForChannel(channelId string, page, perPage int, etag s func (c *Client4) GetPostsByIds(postIds []string) ([]*Post, *Response, error) { js, err := json.Marshal(postIds) if err != nil { - return nil, nil, NewAppError("SearchFilesWithParams", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchFilesWithParams", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.postsRoute()+"/ids", string(js)) if err != nil { @@ -3926,7 +3926,7 @@ func (c *Client4) GetPostsByIds(postIds []string) ([]*Post, *Response, error) { return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetPostsByIds", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPostsByIds", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -3944,7 +3944,7 @@ func (c *Client4) GetFlaggedPostsForUser(userId string, page int, perPage int) ( return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetFlaggedPostsForUser", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetFlaggedPostsForUser", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -3966,7 +3966,7 @@ func (c *Client4) GetFlaggedPostsForUserInTeam(userId string, teamId string, pag return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetFlaggedPostsForUserInTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetFlaggedPostsForUserInTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -3988,7 +3988,7 @@ func (c *Client4) GetFlaggedPostsForUserInChannel(userId string, channelId strin return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetFlaggedPostsForUserInChannel", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetFlaggedPostsForUserInChannel", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -4009,7 +4009,7 @@ func (c *Client4) GetPostsSince(channelId string, time int64, collapsedThreads b return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetPostsSince", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPostsSince", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -4030,7 +4030,7 @@ func (c *Client4) GetPostsAfter(channelId, postId string, page, perPage int, eta return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetPostsAfter", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPostsAfter", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -4051,7 +4051,7 @@ func (c *Client4) GetPostsBefore(channelId, postId string, page, perPage int, et return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetPostsBefore", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPostsBefore", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -4072,7 +4072,7 @@ func (c *Client4) GetPostsAroundLastUnread(userId, channelId string, limitBefore return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetPostsAroundLastUnread", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPostsAroundLastUnread", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -4090,7 +4090,7 @@ func (c *Client4) SearchFiles(teamId string, terms string, isOrSearch bool) (*Fi func (c *Client4) SearchFilesWithParams(teamId string, params *SearchParameter) (*FileInfoList, *Response, error) { js, err := json.Marshal(params) if err != nil { - return nil, nil, NewAppError("SearchFilesWithParams", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchFilesWithParams", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.teamRoute(teamId)+"/files/search", string(js)) if err != nil { @@ -4100,7 +4100,7 @@ func (c *Client4) SearchFilesWithParams(teamId string, params *SearchParameter) var list FileInfoList if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("SearchFilesWithParams", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchFilesWithParams", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -4118,7 +4118,7 @@ func (c *Client4) SearchPosts(teamId string, terms string, isOrSearch bool) (*Po func (c *Client4) SearchPostsWithParams(teamId string, params *SearchParameter) (*PostList, *Response, error) { js, err := json.Marshal(params) if err != nil { - return nil, nil, NewAppError("SearchFilesWithParams", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchFilesWithParams", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } var route string if teamId == "" { @@ -4136,7 +4136,7 @@ func (c *Client4) SearchPostsWithParams(teamId string, params *SearchParameter) return &list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("SearchFilesWithParams", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchFilesWithParams", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &list, BuildResponse(r), nil } @@ -4157,7 +4157,7 @@ func (c *Client4) SearchPostsWithMatches(teamId string, terms string, isOrSearch defer closeBody(r) var psr PostSearchResults if err := json.NewDecoder(r.Body).Decode(&psr); err != nil { - return nil, nil, NewAppError("SearchPostsWithMatches", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchPostsWithMatches", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &psr, BuildResponse(r), nil } @@ -4182,7 +4182,7 @@ func (c *Client4) DoPostActionWithCookie(postId, actionId, selected, cookieStr s Cookie: cookieStr, }) if err != nil { - return nil, NewAppError("DoPostActionWithCookie", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("DoPostActionWithCookie", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } } r, err := c.DoAPIPost(c.postRoute(postId)+"/actions/"+actionId, string(body)) @@ -4203,7 +4203,7 @@ func (c *Client4) GetTopThreadsForTeamSince(teamId string, timeRange string, pag defer closeBody(r) var topThreads *TopThreadList if err := json.NewDecoder(r.Body).Decode(&topThreads); err != nil { - return nil, nil, NewAppError("GetTopThreadsForTeamSince", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTopThreadsForTeamSince", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topThreads, BuildResponse(r), nil } @@ -4223,7 +4223,7 @@ func (c *Client4) GetTopThreadsForUserSince(teamId string, timeRange string, pag defer closeBody(r) var topThreads *TopThreadList if err := json.NewDecoder(r.Body).Decode(&topThreads); err != nil { - return nil, nil, NewAppError("GetTopThreadsForUserSince", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTopThreadsForUserSince", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topThreads, BuildResponse(r), nil } @@ -4235,7 +4235,7 @@ func (c *Client4) GetTopThreadsForUserSince(teamId string, timeRange string, pag func (c *Client4) OpenInteractiveDialog(request OpenDialogRequest) (*Response, error) { b, err := json.Marshal(request) if err != nil { - return nil, NewAppError("OpenInteractiveDialog", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("OpenInteractiveDialog", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost("/actions/dialogs/open", string(b)) if err != nil { @@ -4250,7 +4250,7 @@ func (c *Client4) OpenInteractiveDialog(request OpenDialogRequest) (*Response, e func (c *Client4) SubmitInteractiveDialog(request SubmitDialogRequest) (*SubmitDialogResponse, *Response, error) { b, err := json.Marshal(request) if err != nil { - return nil, nil, NewAppError("SubmitInteractiveDialog", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SubmitInteractiveDialog", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost("/actions/dialogs/submit", string(b)) if err != nil { @@ -4312,7 +4312,7 @@ func (c *Client4) GetFile(fileId string) ([]byte, *Response, error) { data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("GetFile", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("GetFile", "model.client.read_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil } @@ -4327,7 +4327,7 @@ func (c *Client4) DownloadFile(fileId string, download bool) ([]byte, *Response, data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("DownloadFile", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("DownloadFile", "model.client.read_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil } @@ -4342,7 +4342,7 @@ func (c *Client4) GetFileThumbnail(fileId string) ([]byte, *Response, error) { data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("GetFileThumbnail", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("GetFileThumbnail", "model.client.read_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil } @@ -4357,7 +4357,7 @@ func (c *Client4) DownloadFileThumbnail(fileId string, download bool) ([]byte, * data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("DownloadFileThumbnail", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("DownloadFileThumbnail", "model.client.read_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil } @@ -4382,7 +4382,7 @@ func (c *Client4) GetFilePreview(fileId string) ([]byte, *Response, error) { data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("GetFilePreview", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("GetFilePreview", "model.client.read_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil } @@ -4397,7 +4397,7 @@ func (c *Client4) DownloadFilePreview(fileId string, download bool) ([]byte, *Re data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("DownloadFilePreview", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("DownloadFilePreview", "model.client.read_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil } @@ -4412,7 +4412,7 @@ func (c *Client4) GetFileInfo(fileId string) (*FileInfo, *Response, error) { var fi FileInfo if err := json.NewDecoder(r.Body).Decode(&fi); err != nil { - return nil, nil, NewAppError("GetFileInfo", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetFileInfo", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &fi, BuildResponse(r), nil } @@ -4430,7 +4430,7 @@ func (c *Client4) GetFileInfosForPost(postId string, etag string) ([]*FileInfo, return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetFileInfosForPost", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetFileInfosForPost", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -4448,7 +4448,7 @@ func (c *Client4) GetFileInfosForPostIncludeDeleted(postId string, etag string) return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetFileInfosForPostIncludeDeleted", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetFileInfosForPostIncludeDeleted", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -4465,7 +4465,7 @@ func (c *Client4) GenerateSupportPacket() ([]byte, *Response, error) { data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("GetFile", "model.client.read_job_result_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("GetFile", "model.client.read_job_result_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil } @@ -4518,7 +4518,7 @@ func (c *Client4) GetPingWithFullServerStatus() (map[string]string, *Response, e func (c *Client4) TestEmail(config *Config) (*Response, error) { buf, err := json.Marshal(config) if err != nil { - return nil, NewAppError("TestEmail", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("TestEmail", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.testEmailRoute(), buf) if err != nil { @@ -4544,7 +4544,7 @@ func (c *Client4) TestSiteURL(siteURL string) (*Response, error) { func (c *Client4) TestS3Connection(config *Config) (*Response, error) { buf, err := json.Marshal(config) if err != nil { - return nil, NewAppError("TestS3Connection", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("TestS3Connection", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.testS3Route(), buf) if err != nil { @@ -4635,7 +4635,7 @@ func (c *Client4) InvalidateCaches() (*Response, error) { func (c *Client4) UpdateConfig(config *Config) (*Config, *Response, error) { buf, err := json.Marshal(config) if err != nil { - return nil, nil, NewAppError("UpdateConfig", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateConfig", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.configRoute(), buf) if err != nil { @@ -4671,15 +4671,15 @@ func (c *Client4) UploadLicenseFile(data []byte) (*Response, error) { part, err := writer.CreateFormFile("license", "test-license.mattermost-license") if err != nil { - return nil, NewAppError("UploadLicenseFile", "model.client.set_profile_user.no_file.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadLicenseFile", "model.client.set_profile_user.no_file.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if _, err = io.Copy(part, bytes.NewBuffer(data)); err != nil { - return nil, NewAppError("UploadLicenseFile", "model.client.set_profile_user.no_file.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadLicenseFile", "model.client.set_profile_user.no_file.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if err = writer.Close(); err != nil { - return nil, NewAppError("UploadLicenseFile", "model.client.set_profile_user.writer.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadLicenseFile", "model.client.set_profile_user.writer.app_error", nil, "", http.StatusBadRequest).Wrap(err) } rq, err := http.NewRequest("POST", c.APIURL+c.licenseRoute(), bytes.NewReader(body.Bytes())) @@ -4731,7 +4731,7 @@ func (c *Client4) GetAnalyticsOld(name, teamId string) (AnalyticsRows, *Response var rows AnalyticsRows err = json.NewDecoder(r.Body).Decode(&rows) if err != nil { - return nil, BuildResponse(r), NewAppError("GetAnalyticsOld", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetAnalyticsOld", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return rows, BuildResponse(r), nil } @@ -4742,7 +4742,7 @@ func (c *Client4) GetAnalyticsOld(name, teamId string) (AnalyticsRows, *Response func (c *Client4) CreateIncomingWebhook(hook *IncomingWebhook) (*IncomingWebhook, *Response, error) { buf, err := json.Marshal(hook) if err != nil { - return nil, nil, NewAppError("CreateIncomingWebhook", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateIncomingWebhook", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.incomingWebhooksRoute(), buf) if err != nil { @@ -4752,7 +4752,7 @@ func (c *Client4) CreateIncomingWebhook(hook *IncomingWebhook) (*IncomingWebhook var iw IncomingWebhook if err := json.NewDecoder(r.Body).Decode(&iw); err != nil { - return nil, nil, NewAppError("CreateIncomingWebhook", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateIncomingWebhook", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &iw, BuildResponse(r), nil } @@ -4761,7 +4761,7 @@ func (c *Client4) CreateIncomingWebhook(hook *IncomingWebhook) (*IncomingWebhook func (c *Client4) UpdateIncomingWebhook(hook *IncomingWebhook) (*IncomingWebhook, *Response, error) { buf, err := json.Marshal(hook) if err != nil { - return nil, nil, NewAppError("UpdateIncomingWebhook", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateIncomingWebhook", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.incomingWebhookRoute(hook.Id), buf) if err != nil { @@ -4771,7 +4771,7 @@ func (c *Client4) UpdateIncomingWebhook(hook *IncomingWebhook) (*IncomingWebhook var iw IncomingWebhook if err := json.NewDecoder(r.Body).Decode(&iw); err != nil { - return nil, nil, NewAppError("UpdateIncomingWebhook", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateIncomingWebhook", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &iw, BuildResponse(r), nil } @@ -4789,7 +4789,7 @@ func (c *Client4) GetIncomingWebhooks(page int, perPage int, etag string) ([]*In return iwl, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&iwl); err != nil { - return nil, nil, NewAppError("GetIncomingWebhooks", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetIncomingWebhooks", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return iwl, BuildResponse(r), nil } @@ -4807,7 +4807,7 @@ func (c *Client4) GetIncomingWebhooksForTeam(teamId string, page int, perPage in return iwl, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&iwl); err != nil { - return nil, nil, NewAppError("GetIncomingWebhooksForTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetIncomingWebhooksForTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return iwl, BuildResponse(r), nil } @@ -4824,7 +4824,7 @@ func (c *Client4) GetIncomingWebhook(hookID string, etag string) (*IncomingWebho return &iw, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&iw); err != nil { - return nil, nil, NewAppError("GetIncomingWebhook", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetIncomingWebhook", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &iw, BuildResponse(r), nil } @@ -4843,7 +4843,7 @@ func (c *Client4) DeleteIncomingWebhook(hookID string) (*Response, error) { func (c *Client4) CreateOutgoingWebhook(hook *OutgoingWebhook) (*OutgoingWebhook, *Response, error) { buf, err := json.Marshal(hook) if err != nil { - return nil, nil, NewAppError("CreateOutgoingWebhook", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateOutgoingWebhook", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.outgoingWebhooksRoute(), buf) if err != nil { @@ -4852,7 +4852,7 @@ func (c *Client4) CreateOutgoingWebhook(hook *OutgoingWebhook) (*OutgoingWebhook defer closeBody(r) var ow OutgoingWebhook if err := json.NewDecoder(r.Body).Decode(&ow); err != nil { - return nil, nil, NewAppError("CreateOutgoingWebhook", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateOutgoingWebhook", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &ow, BuildResponse(r), nil } @@ -4861,7 +4861,7 @@ func (c *Client4) CreateOutgoingWebhook(hook *OutgoingWebhook) (*OutgoingWebhook func (c *Client4) UpdateOutgoingWebhook(hook *OutgoingWebhook) (*OutgoingWebhook, *Response, error) { buf, err := json.Marshal(hook) if err != nil { - return nil, nil, NewAppError("UpdateOutgoingWebhook", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateOutgoingWebhook", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.outgoingWebhookRoute(hook.Id), buf) if err != nil { @@ -4870,7 +4870,7 @@ func (c *Client4) UpdateOutgoingWebhook(hook *OutgoingWebhook) (*OutgoingWebhook defer closeBody(r) var ow OutgoingWebhook if err := json.NewDecoder(r.Body).Decode(&ow); err != nil { - return nil, nil, NewAppError("UpdateOutgoingWebhook", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateOutgoingWebhook", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &ow, BuildResponse(r), nil } @@ -4888,7 +4888,7 @@ func (c *Client4) GetOutgoingWebhooks(page int, perPage int, etag string) ([]*Ou return owl, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&owl); err != nil { - return nil, nil, NewAppError("GetOutgoingWebhooks", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetOutgoingWebhooks", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return owl, BuildResponse(r), nil } @@ -4902,7 +4902,7 @@ func (c *Client4) GetOutgoingWebhook(hookId string) (*OutgoingWebhook, *Response defer closeBody(r) var ow OutgoingWebhook if err := json.NewDecoder(r.Body).Decode(&ow); err != nil { - return nil, nil, NewAppError("GetOutgoingWebhook", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetOutgoingWebhook", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &ow, BuildResponse(r), nil } @@ -4920,7 +4920,7 @@ func (c *Client4) GetOutgoingWebhooksForChannel(channelId string, page int, perP return owl, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&owl); err != nil { - return nil, nil, NewAppError("GetOutgoingWebhooksForChannel", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetOutgoingWebhooksForChannel", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return owl, BuildResponse(r), nil } @@ -4938,7 +4938,7 @@ func (c *Client4) GetOutgoingWebhooksForTeam(teamId string, page int, perPage in return owl, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&owl); err != nil { - return nil, nil, NewAppError("GetOutgoingWebhooksForTeam", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetOutgoingWebhooksForTeam", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return owl, BuildResponse(r), nil } @@ -4952,7 +4952,7 @@ func (c *Client4) RegenOutgoingHookToken(hookId string) (*OutgoingWebhook, *Resp defer closeBody(r) var ow OutgoingWebhook if err := json.NewDecoder(r.Body).Decode(&ow); err != nil { - return nil, nil, NewAppError("RegenOutgoingHookToken", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("RegenOutgoingHookToken", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &ow, BuildResponse(r), nil } @@ -4979,7 +4979,7 @@ func (c *Client4) GetPreferences(userId string) (Preferences, *Response, error) var prefs Preferences if err := json.NewDecoder(r.Body).Decode(&prefs); err != nil { - return nil, nil, NewAppError("GetPreferences", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPreferences", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return prefs, BuildResponse(r), nil } @@ -4988,7 +4988,7 @@ func (c *Client4) GetPreferences(userId string) (Preferences, *Response, error) func (c *Client4) UpdatePreferences(userId string, preferences Preferences) (*Response, error) { buf, err := json.Marshal(preferences) if err != nil { - return nil, NewAppError("UpdatePreferences", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("UpdatePreferences", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.preferencesRoute(userId), buf) if err != nil { @@ -5002,7 +5002,7 @@ func (c *Client4) UpdatePreferences(userId string, preferences Preferences) (*Re func (c *Client4) DeletePreferences(userId string, preferences Preferences) (*Response, error) { buf, err := json.Marshal(preferences) if err != nil { - return nil, NewAppError("DeletePreferences", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("DeletePreferences", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.preferencesRoute(userId)+"/delete", buf) if err != nil { @@ -5022,7 +5022,7 @@ func (c *Client4) GetPreferencesByCategory(userId string, category string) (Pref defer closeBody(r) var prefs Preferences if err := json.NewDecoder(r.Body).Decode(&prefs); err != nil { - return nil, nil, NewAppError("GetPreferencesByCategory", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPreferencesByCategory", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return prefs, BuildResponse(r), nil } @@ -5038,7 +5038,7 @@ func (c *Client4) GetPreferenceByCategoryAndName(userId string, category string, var pref Preference if err := json.NewDecoder(r.Body).Decode(&pref); err != nil { - return nil, nil, NewAppError("GetPreferenceByCategoryAndName", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPreferenceByCategoryAndName", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &pref, BuildResponse(r), nil } @@ -5087,7 +5087,7 @@ func fileToMultipart(data []byte, filename string) ([]byte, *multipart.Writer, e func (c *Client4) UploadSamlIdpCertificate(data []byte, filename string) (*Response, error) { body, writer, err := fileToMultipart(data, filename) if err != nil { - return nil, NewAppError("UploadSamlIdpCertificate", "model.client.upload_saml_cert.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadSamlIdpCertificate", "model.client.upload_saml_cert.app_error", nil, "", http.StatusBadRequest).Wrap(err) } _, resp, err := c.DoUploadFile(c.samlRoute()+"/certificate/idp", body, writer.FormDataContentType()) @@ -5099,7 +5099,7 @@ func (c *Client4) UploadSamlIdpCertificate(data []byte, filename string) (*Respo func (c *Client4) UploadSamlPublicCertificate(data []byte, filename string) (*Response, error) { body, writer, err := fileToMultipart(data, filename) if err != nil { - return nil, NewAppError("UploadSamlPublicCertificate", "model.client.upload_saml_cert.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadSamlPublicCertificate", "model.client.upload_saml_cert.app_error", nil, "", http.StatusBadRequest).Wrap(err) } _, resp, err := c.DoUploadFile(c.samlRoute()+"/certificate/public", body, writer.FormDataContentType()) @@ -5111,7 +5111,7 @@ func (c *Client4) UploadSamlPublicCertificate(data []byte, filename string) (*Re func (c *Client4) UploadSamlPrivateCertificate(data []byte, filename string) (*Response, error) { body, writer, err := fileToMultipart(data, filename) if err != nil { - return nil, NewAppError("UploadSamlPrivateCertificate", "model.client.upload_saml_cert.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadSamlPrivateCertificate", "model.client.upload_saml_cert.app_error", nil, "", http.StatusBadRequest).Wrap(err) } _, resp, err := c.DoUploadFile(c.samlRoute()+"/certificate/private", body, writer.FormDataContentType()) @@ -5158,7 +5158,7 @@ func (c *Client4) GetSamlCertificateStatus() (*SamlCertificateStatus, *Response, var status SamlCertificateStatus if err := json.NewDecoder(r.Body).Decode(&status); err != nil { - return nil, nil, NewAppError("GetSamlCertificateStatus", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetSamlCertificateStatus", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &status, BuildResponse(r), nil } @@ -5174,7 +5174,7 @@ func (c *Client4) GetSamlMetadataFromIdp(samlMetadataURL string) (*SamlMetadataR defer closeBody(r) var resp SamlMetadataResponse if err := json.NewDecoder(r.Body).Decode(&resp); err != nil { - return nil, nil, NewAppError("GetSamlMetadataFromIdp", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetSamlMetadataFromIdp", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &resp, BuildResponse(r), nil } @@ -5188,7 +5188,7 @@ func (c *Client4) ResetSamlAuthDataToEmail(includeDeleted bool, dryRun bool, use } b, err := json.Marshal(params) if err != nil { - return 0, nil, NewAppError("ResetSamlAuthDataToEmail", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return 0, nil, NewAppError("ResetSamlAuthDataToEmail", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.samlRoute()+"/reset_auth_data", b) if err != nil { @@ -5198,7 +5198,7 @@ func (c *Client4) ResetSamlAuthDataToEmail(includeDeleted bool, dryRun bool, use respBody := map[string]int64{} err = json.NewDecoder(r.Body).Decode(&respBody) if err != nil { - return 0, BuildResponse(r), NewAppError("Api4.ResetSamlAuthDataToEmail", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return 0, BuildResponse(r), NewAppError("Api4.ResetSamlAuthDataToEmail", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return respBody["num_affected"], BuildResponse(r), nil } @@ -5209,7 +5209,7 @@ func (c *Client4) ResetSamlAuthDataToEmail(includeDeleted bool, dryRun bool, use func (c *Client4) CreateComplianceReport(report *Compliance) (*Compliance, *Response, error) { buf, err := json.Marshal(report) if err != nil { - return nil, nil, NewAppError("CreateComplianceReport", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateComplianceReport", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.complianceReportsRoute(), buf) if err != nil { @@ -5218,7 +5218,7 @@ func (c *Client4) CreateComplianceReport(report *Compliance) (*Compliance, *Resp defer closeBody(r) var comp Compliance if err := json.NewDecoder(r.Body).Decode(&comp); err != nil { - return nil, nil, NewAppError("CreateComplianceReport", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateComplianceReport", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &comp, BuildResponse(r), nil } @@ -5233,7 +5233,7 @@ func (c *Client4) GetComplianceReports(page, perPage int) (Compliances, *Respons defer closeBody(r) var comp Compliances if err := json.NewDecoder(r.Body).Decode(&comp); err != nil { - return nil, nil, NewAppError("GetComplianceReports", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetComplianceReports", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return comp, BuildResponse(r), nil } @@ -5247,7 +5247,7 @@ func (c *Client4) GetComplianceReport(reportId string) (*Compliance, *Response, defer closeBody(r) var comp Compliance if err := json.NewDecoder(r.Body).Decode(&comp); err != nil { - return nil, nil, NewAppError("GetComplianceReport", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetComplianceReport", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &comp, BuildResponse(r), nil } @@ -5275,7 +5275,7 @@ func (c *Client4) DownloadComplianceReport(reportId string) ([]byte, *Response, data, err := io.ReadAll(rp.Body) if err != nil { - return nil, BuildResponse(rp), NewAppError("DownloadComplianceReport", "model.client.read_file.app_error", nil, err.Error(), rp.StatusCode) + return nil, BuildResponse(rp), NewAppError("DownloadComplianceReport", "model.client.read_file.app_error", nil, "", rp.StatusCode).Wrap(err) } return data, BuildResponse(rp), nil @@ -5292,7 +5292,7 @@ func (c *Client4) GetClusterStatus() ([]*ClusterInfo, *Response, error) { defer closeBody(r) var list []*ClusterInfo if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetClusterStatus", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetClusterStatus", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -5307,7 +5307,7 @@ func (c *Client4) SyncLdap(includeRemovedMembers bool) (*Response, error) { "include_removed_members": includeRemovedMembers, }) if err != nil { - return nil, NewAppError("SyncLdap", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("SyncLdap", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.ldapRoute()+"/sync", reqBody) if err != nil { @@ -5343,7 +5343,7 @@ func (c *Client4) GetLdapGroups() ([]*Group, *Response, error) { Groups []*Group `json:"groups"` }{} if err := json.NewDecoder(r.Body).Decode(&responseData); err != nil { - return nil, BuildResponse(r), NewAppError("Api4.GetLdapGroups", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("Api4.GetLdapGroups", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } for i := range responseData.Groups { responseData.Groups[i].DisplayName = *responseData.Groups[i].Name @@ -5364,7 +5364,7 @@ func (c *Client4) LinkLdapGroup(dn string) (*Group, *Response, error) { var g Group if err := json.NewDecoder(r.Body).Decode(&g); err != nil { - return nil, nil, NewAppError("LinkLdapGroup", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("LinkLdapGroup", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &g, BuildResponse(r), nil } @@ -5381,7 +5381,7 @@ func (c *Client4) UnlinkLdapGroup(dn string) (*Group, *Response, error) { var g Group if err := json.NewDecoder(r.Body).Decode(&g); err != nil { - return nil, nil, NewAppError("UnlinkLdapGroup", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UnlinkLdapGroup", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &g, BuildResponse(r), nil } @@ -5415,7 +5415,7 @@ func (c *Client4) GetGroupsByChannel(channelId string, opts GroupSearchOpts) ([] Count int `json:"total_group_count"` }{} if err := json.NewDecoder(r.Body).Decode(&responseData); err != nil { - return nil, 0, BuildResponse(r), NewAppError("Api4.GetGroupsByChannel", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, BuildResponse(r), NewAppError("Api4.GetGroupsByChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return responseData.Groups, responseData.Count, BuildResponse(r), nil @@ -5438,7 +5438,7 @@ func (c *Client4) GetGroupsByTeam(teamId string, opts GroupSearchOpts) ([]*Group Count int `json:"total_group_count"` }{} if err := json.NewDecoder(r.Body).Decode(&responseData); err != nil { - return nil, 0, BuildResponse(r), NewAppError("Api4.GetGroupsByTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, BuildResponse(r), NewAppError("Api4.GetGroupsByTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return responseData.Groups, responseData.Count, BuildResponse(r), nil @@ -5460,7 +5460,7 @@ func (c *Client4) GetGroupsAssociatedToChannelsByTeam(teamId string, opts GroupS GroupsAssociatedToChannels map[string][]*GroupWithSchemeAdmin `json:"groups"` }{} if err := json.NewDecoder(r.Body).Decode(&responseData); err != nil { - return nil, BuildResponse(r), NewAppError("Api4.GetGroupsAssociatedToChannelsByTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("Api4.GetGroupsAssociatedToChannelsByTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return responseData.GroupsAssociatedToChannels, BuildResponse(r), nil @@ -5493,7 +5493,7 @@ func (c *Client4) GetGroups(opts GroupSearchOpts) ([]*Group, *Response, error) { var list []*Group if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetGroups", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetGroups", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -5513,7 +5513,7 @@ func (c *Client4) GetGroupsByUserId(userId string) ([]*Group, *Response, error) defer closeBody(r) var list []*Group if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetGroupsByUserId", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetGroupsByUserId", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -5548,7 +5548,7 @@ func (c *Client4) MigrateAuthToSaml(fromAuthService string, usersMap map[string] func (c *Client4) UploadLdapPublicCertificate(data []byte) (*Response, error) { body, writer, err := fileToMultipart(data, LdapPublicCertificateName) if err != nil { - return nil, NewAppError("UploadLdapPublicCertificate", "model.client.upload_ldap_cert.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadLdapPublicCertificate", "model.client.upload_ldap_cert.app_error", nil, "", http.StatusBadRequest).Wrap(err) } _, resp, err := c.DoUploadFile(c.ldapRoute()+"/certificate/public", body, writer.FormDataContentType()) @@ -5559,7 +5559,7 @@ func (c *Client4) UploadLdapPublicCertificate(data []byte) (*Response, error) { func (c *Client4) UploadLdapPrivateCertificate(data []byte) (*Response, error) { body, writer, err := fileToMultipart(data, LdapPrivateKeyName) if err != nil { - return nil, NewAppError("UploadLdapPrivateCertificate", "model.client.upload_Ldap_cert.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadLdapPrivateCertificate", "model.client.upload_Ldap_cert.app_error", nil, "", http.StatusBadRequest).Wrap(err) } _, resp, err := c.DoUploadFile(c.ldapRoute()+"/certificate/private", body, writer.FormDataContentType()) @@ -5600,7 +5600,7 @@ func (c *Client4) GetAudits(page int, perPage int, etag string) (Audits, *Respon var audits Audits err = json.NewDecoder(r.Body).Decode(&audits) if err != nil { - return nil, BuildResponse(r), NewAppError("GetAudits", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetAudits", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return audits, BuildResponse(r), nil } @@ -5621,7 +5621,7 @@ func (c *Client4) GetBrandImage() ([]byte, *Response, error) { data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("GetBrandImage", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("GetBrandImage", "model.client.read_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil @@ -5643,15 +5643,15 @@ func (c *Client4) UploadBrandImage(data []byte) (*Response, error) { part, err := writer.CreateFormFile("image", "brand.png") if err != nil { - return nil, NewAppError("UploadBrandImage", "model.client.set_profile_user.no_file.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadBrandImage", "model.client.set_profile_user.no_file.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if _, err = io.Copy(part, bytes.NewBuffer(data)); err != nil { - return nil, NewAppError("UploadBrandImage", "model.client.set_profile_user.no_file.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadBrandImage", "model.client.set_profile_user.no_file.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if err = writer.Close(); err != nil { - return nil, NewAppError("UploadBrandImage", "model.client.set_profile_user.writer.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("UploadBrandImage", "model.client.set_profile_user.writer.app_error", nil, "", http.StatusBadRequest).Wrap(err) } rq, err := http.NewRequest("POST", c.APIURL+c.brandRoute()+"/image", bytes.NewReader(body.Bytes())) @@ -5708,7 +5708,7 @@ func (c *Client4) PostLog(message map[string]string) (map[string]string, *Respon func (c *Client4) CreateOAuthApp(app *OAuthApp) (*OAuthApp, *Response, error) { buf, err := json.Marshal(app) if err != nil { - return nil, nil, NewAppError("CreateOAuthApp", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateOAuthApp", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.oAuthAppsRoute(), buf) if err != nil { @@ -5718,7 +5718,7 @@ func (c *Client4) CreateOAuthApp(app *OAuthApp) (*OAuthApp, *Response, error) { var oapp OAuthApp if err := json.NewDecoder(r.Body).Decode(&oapp); err != nil { - return nil, nil, NewAppError("CreateOAuthApp", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateOAuthApp", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &oapp, BuildResponse(r), nil } @@ -5727,7 +5727,7 @@ func (c *Client4) CreateOAuthApp(app *OAuthApp) (*OAuthApp, *Response, error) { func (c *Client4) UpdateOAuthApp(app *OAuthApp) (*OAuthApp, *Response, error) { buf, err := json.Marshal(app) if err != nil { - return nil, nil, NewAppError("UpdateOAuthApp", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateOAuthApp", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.oAuthAppRoute(app.Id), buf) if err != nil { @@ -5736,7 +5736,7 @@ func (c *Client4) UpdateOAuthApp(app *OAuthApp) (*OAuthApp, *Response, error) { defer closeBody(r) var oapp OAuthApp if err := json.NewDecoder(r.Body).Decode(&oapp); err != nil { - return nil, nil, NewAppError("UpdateOAuthApp", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateOAuthApp", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &oapp, BuildResponse(r), nil } @@ -5751,7 +5751,7 @@ func (c *Client4) GetOAuthApps(page, perPage int) ([]*OAuthApp, *Response, error defer closeBody(r) var list []*OAuthApp if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetOAuthApps", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetOAuthApps", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -5765,7 +5765,7 @@ func (c *Client4) GetOAuthApp(appId string) (*OAuthApp, *Response, error) { defer closeBody(r) var oapp OAuthApp if err := json.NewDecoder(r.Body).Decode(&oapp); err != nil { - return nil, nil, NewAppError("GetOAuthApp", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetOAuthApp", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &oapp, BuildResponse(r), nil } @@ -5779,7 +5779,7 @@ func (c *Client4) GetOAuthAppInfo(appId string) (*OAuthApp, *Response, error) { defer closeBody(r) var oapp OAuthApp if err := json.NewDecoder(r.Body).Decode(&oapp); err != nil { - return nil, nil, NewAppError("GetOAuthAppInfo", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetOAuthAppInfo", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &oapp, BuildResponse(r), nil } @@ -5803,7 +5803,7 @@ func (c *Client4) RegenerateOAuthAppSecret(appId string) (*OAuthApp, *Response, defer closeBody(r) var oapp OAuthApp if err := json.NewDecoder(r.Body).Decode(&oapp); err != nil { - return nil, nil, NewAppError("RegenerateOAuthAppSecret", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("RegenerateOAuthAppSecret", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &oapp, BuildResponse(r), nil } @@ -5818,7 +5818,7 @@ func (c *Client4) GetAuthorizedOAuthAppsForUser(userId string, page, perPage int defer closeBody(r) var list []*OAuthApp if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetAuthorizedOAuthAppsForUser", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetAuthorizedOAuthAppsForUser", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -5827,7 +5827,7 @@ func (c *Client4) GetAuthorizedOAuthAppsForUser(userId string, page, perPage int func (c *Client4) AuthorizeOAuthApp(authRequest *AuthorizeRequest) (string, *Response, error) { buf, err := json.Marshal(authRequest) if err != nil { - return "", BuildResponse(nil), NewAppError("AuthorizeOAuthApp", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return "", BuildResponse(nil), NewAppError("AuthorizeOAuthApp", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIRequestBytes(http.MethodPost, c.URL+"/oauth/authorize", buf, "") if err != nil { @@ -5874,7 +5874,7 @@ func (c *Client4) GetOAuthAccessToken(data url.Values) (*AccessResponse, *Respon var ar *AccessResponse err = json.NewDecoder(rp.Body).Decode(&ar) if err != nil { - return nil, BuildResponse(rp), NewAppError(url, "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(rp), NewAppError(url, "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ar, BuildResponse(rp), nil @@ -5926,7 +5926,7 @@ func (c *Client4) GetDataRetentionPolicy() (*GlobalRetentionPolicy, *Response, e defer closeBody(r) var p GlobalRetentionPolicy if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("GetDataRetentionPolicy", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetDataRetentionPolicy", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -5941,7 +5941,7 @@ func (c *Client4) GetDataRetentionPolicyByID(policyID string) (*RetentionPolicyW var p RetentionPolicyWithTeamAndChannelCounts if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("GetDataRetentionPolicyByID", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetDataRetentionPolicyByID", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -5958,7 +5958,7 @@ func (c *Client4) GetDataRetentionPoliciesCount() (int64, *Response, error) { var countObj CountBody err = json.NewDecoder(r.Body).Decode(&countObj) if err != nil { - return 0, nil, NewAppError("Client4.GetDataRetentionPoliciesCount", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return 0, nil, NewAppError("Client4.GetDataRetentionPoliciesCount", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return countObj.TotalCount, BuildResponse(r), nil } @@ -5974,7 +5974,7 @@ func (c *Client4) GetDataRetentionPolicies(page, perPage int) (*RetentionPolicyW var p RetentionPolicyWithTeamAndChannelCountsList if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("GetDataRetentionPolicies", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetDataRetentionPolicies", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -5984,7 +5984,7 @@ func (c *Client4) GetDataRetentionPolicies(page, perPage int) (*RetentionPolicyW func (c *Client4) CreateDataRetentionPolicy(policy *RetentionPolicyWithTeamAndChannelIDs) (*RetentionPolicyWithTeamAndChannelCounts, *Response, error) { policyJSON, err := json.Marshal(policy) if err != nil { - return nil, nil, NewAppError("CreateDataRetentionPolicy", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateDataRetentionPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.dataRetentionRoute()+"/policies", policyJSON) if err != nil { @@ -5993,7 +5993,7 @@ func (c *Client4) CreateDataRetentionPolicy(policy *RetentionPolicyWithTeamAndCh defer closeBody(r) var p RetentionPolicyWithTeamAndChannelCounts if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("CreateDataRetentionPolicy", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateDataRetentionPolicy", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -6013,7 +6013,7 @@ func (c *Client4) DeleteDataRetentionPolicy(policyID string) (*Response, error) func (c *Client4) PatchDataRetentionPolicy(patch *RetentionPolicyWithTeamAndChannelIDs) (*RetentionPolicyWithTeamAndChannelCounts, *Response, error) { patchJSON, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("PatchDataRetentionPolicy", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchDataRetentionPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPatchBytes(c.dataRetentionPolicyRoute(patch.ID), patchJSON) if err != nil { @@ -6022,7 +6022,7 @@ func (c *Client4) PatchDataRetentionPolicy(patch *RetentionPolicyWithTeamAndChan defer closeBody(r) var p RetentionPolicyWithTeamAndChannelCounts if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("PatchDataRetentionPolicy", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchDataRetentionPolicy", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -6037,7 +6037,7 @@ func (c *Client4) GetTeamsForRetentionPolicy(policyID string, page, perPage int) var teams *TeamsWithCount err = json.NewDecoder(r.Body).Decode(&teams) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.GetTeamsForRetentionPolicy", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.GetTeamsForRetentionPolicy", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return teams, BuildResponse(r), nil } @@ -6046,7 +6046,7 @@ func (c *Client4) GetTeamsForRetentionPolicy(policyID string, page, perPage int) func (c *Client4) SearchTeamsForRetentionPolicy(policyID string, term string) ([]*Team, *Response, error) { body, err := json.Marshal(map[string]any{"term": term}) if err != nil { - return nil, nil, NewAppError("SearchTeamsForRetentionPolicy", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchTeamsForRetentionPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.dataRetentionPolicyRoute(policyID)+"/teams/search", body) if err != nil { @@ -6055,7 +6055,7 @@ func (c *Client4) SearchTeamsForRetentionPolicy(policyID string, term string) ([ var teams []*Team err = json.NewDecoder(r.Body).Decode(&teams) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.SearchTeamsForRetentionPolicy", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.SearchTeamsForRetentionPolicy", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return teams, BuildResponse(r), nil } @@ -6065,7 +6065,7 @@ func (c *Client4) SearchTeamsForRetentionPolicy(policyID string, term string) ([ func (c *Client4) AddTeamsToRetentionPolicy(policyID string, teamIDs []string) (*Response, error) { body, err := json.Marshal(teamIDs) if err != nil { - return nil, NewAppError("AddTeamsToRetentionPolicy", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("AddTeamsToRetentionPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.dataRetentionPolicyRoute(policyID)+"/teams", body) if err != nil { @@ -6080,7 +6080,7 @@ func (c *Client4) AddTeamsToRetentionPolicy(policyID string, teamIDs []string) ( func (c *Client4) RemoveTeamsFromRetentionPolicy(policyID string, teamIDs []string) (*Response, error) { body, err := json.Marshal(teamIDs) if err != nil { - return nil, NewAppError("RemoveTeamsFromRetentionPolicy", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("RemoveTeamsFromRetentionPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIDeleteBytes(c.dataRetentionPolicyRoute(policyID)+"/teams", body) if err != nil { @@ -6100,7 +6100,7 @@ func (c *Client4) GetChannelsForRetentionPolicy(policyID string, page, perPage i var channels *ChannelsWithCount err = json.NewDecoder(r.Body).Decode(&channels) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.GetChannelsForRetentionPolicy", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.GetChannelsForRetentionPolicy", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return channels, BuildResponse(r), nil } @@ -6109,7 +6109,7 @@ func (c *Client4) GetChannelsForRetentionPolicy(policyID string, page, perPage i func (c *Client4) SearchChannelsForRetentionPolicy(policyID string, term string) (ChannelListWithTeamData, *Response, error) { body, err := json.Marshal(map[string]any{"term": term}) if err != nil { - return nil, nil, NewAppError("SearchChannelsForRetentionPolicy", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchChannelsForRetentionPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.dataRetentionPolicyRoute(policyID)+"/channels/search", body) if err != nil { @@ -6118,7 +6118,7 @@ func (c *Client4) SearchChannelsForRetentionPolicy(policyID string, term string) var channels ChannelListWithTeamData err = json.NewDecoder(r.Body).Decode(&channels) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.SearchChannelsForRetentionPolicy", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.SearchChannelsForRetentionPolicy", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return channels, BuildResponse(r), nil } @@ -6128,7 +6128,7 @@ func (c *Client4) SearchChannelsForRetentionPolicy(policyID string, term string) func (c *Client4) AddChannelsToRetentionPolicy(policyID string, channelIDs []string) (*Response, error) { body, err := json.Marshal(channelIDs) if err != nil { - return nil, NewAppError("AddChannelsToRetentionPolicy", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("AddChannelsToRetentionPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.dataRetentionPolicyRoute(policyID)+"/channels", body) if err != nil { @@ -6143,7 +6143,7 @@ func (c *Client4) AddChannelsToRetentionPolicy(policyID string, channelIDs []str func (c *Client4) RemoveChannelsFromRetentionPolicy(policyID string, channelIDs []string) (*Response, error) { body, err := json.Marshal(channelIDs) if err != nil { - return nil, NewAppError("RemoveChannelsFromRetentionPolicy", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("RemoveChannelsFromRetentionPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIDeleteBytes(c.dataRetentionPolicyRoute(policyID)+"/channels", body) if err != nil { @@ -6162,7 +6162,7 @@ func (c *Client4) GetTeamPoliciesForUser(userID string, offset, limit int) (*Ret var teams RetentionPolicyForTeamList err = json.NewDecoder(r.Body).Decode(&teams) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.GetTeamPoliciesForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.GetTeamPoliciesForUser", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return &teams, BuildResponse(r), nil } @@ -6176,7 +6176,7 @@ func (c *Client4) GetChannelPoliciesForUser(userID string, offset, limit int) (* var channels RetentionPolicyForChannelList err = json.NewDecoder(r.Body).Decode(&channels) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.GetChannelPoliciesForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.GetChannelPoliciesForUser", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return &channels, BuildResponse(r), nil } @@ -6187,7 +6187,7 @@ func (c *Client4) GetChannelPoliciesForUser(userID string, offset, limit int) (* func (c *Client4) CreateCommand(cmd *Command) (*Command, *Response, error) { buf, err := json.Marshal(cmd) if err != nil { - return nil, nil, NewAppError("CreateCommand", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateCommand", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.commandsRoute(), buf) if err != nil { @@ -6197,7 +6197,7 @@ func (c *Client4) CreateCommand(cmd *Command) (*Command, *Response, error) { var command Command if err := json.NewDecoder(r.Body).Decode(&command); err != nil { - return nil, nil, NewAppError("CreateCommand", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateCommand", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &command, BuildResponse(r), nil } @@ -6206,7 +6206,7 @@ func (c *Client4) CreateCommand(cmd *Command) (*Command, *Response, error) { func (c *Client4) UpdateCommand(cmd *Command) (*Command, *Response, error) { buf, err := json.Marshal(cmd) if err != nil { - return nil, nil, NewAppError("UpdateCommand", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateCommand", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.commandRoute(cmd.Id), buf) if err != nil { @@ -6215,7 +6215,7 @@ func (c *Client4) UpdateCommand(cmd *Command) (*Command, *Response, error) { defer closeBody(r) var command Command if err := json.NewDecoder(r.Body).Decode(&command); err != nil { - return nil, nil, NewAppError("UpdateCommand", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateCommand", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &command, BuildResponse(r), nil } @@ -6225,7 +6225,7 @@ func (c *Client4) MoveCommand(teamId string, commandId string) (*Response, error cmr := CommandMoveRequest{TeamId: teamId} buf, err := json.Marshal(cmr) if err != nil { - return nil, NewAppError("MoveCommand", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("MoveCommand", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.commandMoveRoute(commandId), buf) if err != nil { @@ -6256,7 +6256,7 @@ func (c *Client4) ListCommands(teamId string, customOnly bool) ([]*Command, *Res var list []*Command if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("ListCommands", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("ListCommands", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6271,7 +6271,7 @@ func (c *Client4) ListCommandAutocompleteSuggestions(userInput, teamId string) ( defer closeBody(r) var list []AutocompleteSuggestion if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("ListCommandAutocompleteSuggestions", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("ListCommandAutocompleteSuggestions", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6286,7 +6286,7 @@ func (c *Client4) GetCommandById(cmdId string) (*Command, *Response, error) { defer closeBody(r) var command Command if err := json.NewDecoder(r.Body).Decode(&command); err != nil { - return nil, nil, NewAppError("GetCommandById", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetCommandById", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &command, BuildResponse(r), nil } @@ -6299,7 +6299,7 @@ func (c *Client4) ExecuteCommand(channelId, command string) (*CommandResponse, * } buf, err := json.Marshal(commandArgs) if err != nil { - return nil, nil, NewAppError("ExecuteCommand", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("ExecuteCommand", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.commandsRoute()+"/execute", buf) if err != nil { @@ -6309,7 +6309,7 @@ func (c *Client4) ExecuteCommand(channelId, command string) (*CommandResponse, * response, err := CommandResponseFromJSON(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("ExecuteCommand", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("ExecuteCommand", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return response, BuildResponse(r), nil } @@ -6324,7 +6324,7 @@ func (c *Client4) ExecuteCommandWithTeam(channelId, teamId, command string) (*Co } buf, err := json.Marshal(commandArgs) if err != nil { - return nil, nil, NewAppError("ExecuteCommandWithTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("ExecuteCommandWithTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.commandsRoute()+"/execute", buf) if err != nil { @@ -6334,7 +6334,7 @@ func (c *Client4) ExecuteCommandWithTeam(channelId, teamId, command string) (*Co response, err := CommandResponseFromJSON(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("ExecuteCommandWithTeam", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("ExecuteCommandWithTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return response, BuildResponse(r), nil } @@ -6348,7 +6348,7 @@ func (c *Client4) ListAutocompleteCommands(teamId string) ([]*Command, *Response defer closeBody(r) var list []*Command if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("ListAutocompleteCommands", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("ListAutocompleteCommands", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6377,7 +6377,7 @@ func (c *Client4) GetUserStatus(userId, etag string) (*Status, *Response, error) return &s, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&s); err != nil { - return nil, nil, NewAppError("GetUserStatus", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUserStatus", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &s, BuildResponse(r), nil } @@ -6391,7 +6391,7 @@ func (c *Client4) GetUsersStatusesByIds(userIds []string) ([]*Status, *Response, defer closeBody(r) var list []*Status if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsersStatusesByIds", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsersStatusesByIds", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6400,7 +6400,7 @@ func (c *Client4) GetUsersStatusesByIds(userIds []string) ([]*Status, *Response, func (c *Client4) UpdateUserStatus(userId string, userStatus *Status) (*Status, *Response, error) { buf, err := json.Marshal(userStatus) if err != nil { - return nil, nil, NewAppError("UpdateUserStatus", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateUserStatus", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.userStatusRoute(userId), buf) if err != nil { @@ -6409,7 +6409,7 @@ func (c *Client4) UpdateUserStatus(userId string, userStatus *Status) (*Status, defer closeBody(r) var s Status if err := json.NewDecoder(r.Body).Decode(&s); err != nil { - return nil, nil, NewAppError("UpdateUserStatus", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateUserStatus", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &s, BuildResponse(r), nil } @@ -6420,7 +6420,7 @@ func (c *Client4) UpdateUserStatus(userId string, userStatus *Status) (*Status, func (c *Client4) UpdateUserCustomStatus(userId string, userCustomStatus *CustomStatus) (*CustomStatus, *Response, error) { buf, err := json.Marshal(userCustomStatus) if err != nil { - return nil, nil, NewAppError("UpdateUserCustomStatus", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateUserCustomStatus", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.userStatusRoute(userId)+"/custom", buf) if err != nil { @@ -6474,7 +6474,7 @@ func (c *Client4) CreateEmoji(emoji *Emoji, image []byte, filename string) (*Emo emojiJSON, err := json.Marshal(emoji) if err != nil { - return nil, nil, NewAppError("CreateEmoji", "api.marshal_error", nil, err.Error(), 0) + return nil, nil, NewAppError("CreateEmoji", "api.marshal_error", nil, "", 0).Wrap(err) } if err := writer.WriteField("emoji", string(emojiJSON)); err != nil { @@ -6499,7 +6499,7 @@ func (c *Client4) GetEmojiList(page, perPage int) ([]*Emoji, *Response, error) { var list []*Emoji if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetEmojiList", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetEmojiList", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6515,7 +6515,7 @@ func (c *Client4) GetSortedEmojiList(page, perPage int, sort string) ([]*Emoji, defer closeBody(r) var list []*Emoji if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetSortedEmojiList", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetSortedEmojiList", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6539,7 +6539,7 @@ func (c *Client4) GetEmoji(emojiId string) (*Emoji, *Response, error) { defer closeBody(r) var e Emoji if err := json.NewDecoder(r.Body).Decode(&e); err != nil { - return nil, nil, NewAppError("GetEmoji", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetEmoji", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &e, BuildResponse(r), nil } @@ -6553,7 +6553,7 @@ func (c *Client4) GetEmojiByName(name string) (*Emoji, *Response, error) { defer closeBody(r) var e Emoji if err := json.NewDecoder(r.Body).Decode(&e); err != nil { - return nil, nil, NewAppError("GetEmojiByName", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetEmojiByName", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &e, BuildResponse(r), nil } @@ -6568,7 +6568,7 @@ func (c *Client4) GetEmojiImage(emojiId string) ([]byte, *Response, error) { data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("GetEmojiImage", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("GetEmojiImage", "model.client.read_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil @@ -6578,7 +6578,7 @@ func (c *Client4) GetEmojiImage(emojiId string) ([]byte, *Response, error) { func (c *Client4) SearchEmoji(search *EmojiSearch) ([]*Emoji, *Response, error) { buf, err := json.Marshal(search) if err != nil { - return nil, nil, NewAppError("SearchEmoji", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchEmoji", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.emojisRoute()+"/search", buf) if err != nil { @@ -6587,7 +6587,7 @@ func (c *Client4) SearchEmoji(search *EmojiSearch) ([]*Emoji, *Response, error) defer closeBody(r) var list []*Emoji if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("SearchEmoji", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SearchEmoji", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6602,7 +6602,7 @@ func (c *Client4) AutocompleteEmoji(name string, etag string) ([]*Emoji, *Respon defer closeBody(r) var list []*Emoji if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("AutocompleteEmoji", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("AutocompleteEmoji", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6613,7 +6613,7 @@ func (c *Client4) AutocompleteEmoji(name string, etag string) ([]*Emoji, *Respon func (c *Client4) SaveReaction(reaction *Reaction) (*Reaction, *Response, error) { buf, err := json.Marshal(reaction) if err != nil { - return nil, nil, NewAppError("SaveReaction", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SaveReaction", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.reactionsRoute(), buf) if err != nil { @@ -6622,7 +6622,7 @@ func (c *Client4) SaveReaction(reaction *Reaction) (*Reaction, *Response, error) defer closeBody(r) var re Reaction if err := json.NewDecoder(r.Body).Decode(&re); err != nil { - return nil, nil, NewAppError("SaveReaction", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("SaveReaction", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &re, BuildResponse(r), nil } @@ -6636,7 +6636,7 @@ func (c *Client4) GetReactions(postId string) ([]*Reaction, *Response, error) { defer closeBody(r) var list []*Reaction if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetReactions", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetReactions", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6660,7 +6660,7 @@ func (c *Client4) GetBulkReactions(postIds []string) (map[string][]*Reaction, *R defer closeBody(r) reactions := map[string][]*Reaction{} if err := json.NewDecoder(r.Body).Decode(&reactions); err != nil { - return nil, nil, NewAppError("GetBulkReactions", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetBulkReactions", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return reactions, BuildResponse(r), nil } @@ -6674,7 +6674,7 @@ func (c *Client4) GetTopReactionsForTeamSince(teamId string, timeRange string, p defer closeBody(r) var topReactions *TopReactionList if err := json.NewDecoder(r.Body).Decode(&topReactions); err != nil { - return nil, nil, NewAppError("GetTopReactionsForTeamSince", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTopReactionsForTeamSince", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topReactions, BuildResponse(r), nil } @@ -6693,7 +6693,7 @@ func (c *Client4) GetTopReactionsForUserSince(teamId string, timeRange string, p defer closeBody(r) var topReactions *TopReactionList if err := json.NewDecoder(r.Body).Decode(&topReactions); err != nil { - return nil, nil, NewAppError("GetTopReactionsForUserSince", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTopReactionsForUserSince", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return topReactions, BuildResponse(r), nil } @@ -6738,7 +6738,7 @@ func (c *Client4) GetJob(id string) (*Job, *Response, error) { defer closeBody(r) var j Job if err := json.NewDecoder(r.Body).Decode(&j); err != nil { - return nil, nil, NewAppError("GetJob", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetJob", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &j, BuildResponse(r), nil } @@ -6752,7 +6752,7 @@ func (c *Client4) GetJobs(page int, perPage int) ([]*Job, *Response, error) { defer closeBody(r) var list []*Job if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetJobs", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetJobs", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6766,7 +6766,7 @@ func (c *Client4) GetJobsByType(jobType string, page int, perPage int) ([]*Job, defer closeBody(r) var list []*Job if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetJobsByType", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetJobsByType", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6775,7 +6775,7 @@ func (c *Client4) GetJobsByType(jobType string, page int, perPage int) ([]*Job, func (c *Client4) CreateJob(job *Job) (*Job, *Response, error) { buf, err := json.Marshal(job) if err != nil { - return nil, nil, NewAppError("CreateJob", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateJob", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.jobsRoute(), buf) if err != nil { @@ -6784,7 +6784,7 @@ func (c *Client4) CreateJob(job *Job) (*Job, *Response, error) { defer closeBody(r) var j Job if err := json.NewDecoder(r.Body).Decode(&j); err != nil { - return nil, nil, NewAppError("CreateJob", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateJob", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &j, BuildResponse(r), nil } @@ -6809,7 +6809,7 @@ func (c *Client4) DownloadJob(jobId string) ([]byte, *Response, error) { data, err := io.ReadAll(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError("GetFile", "model.client.read_job_result_file.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("GetFile", "model.client.read_job_result_file.app_error", nil, "", r.StatusCode).Wrap(err) } return data, BuildResponse(r), nil } @@ -6825,7 +6825,7 @@ func (c *Client4) GetAllRoles() ([]*Role, *Response, error) { defer closeBody(r) var list []*Role if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetAllRoles", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetAllRoles", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6839,7 +6839,7 @@ func (c *Client4) GetRole(id string) (*Role, *Response, error) { defer closeBody(r) var role Role if err := json.NewDecoder(r.Body).Decode(&role); err != nil { - return nil, nil, NewAppError("GetRole", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetRole", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &role, BuildResponse(r), nil } @@ -6853,7 +6853,7 @@ func (c *Client4) GetRoleByName(name string) (*Role, *Response, error) { defer closeBody(r) var role Role if err := json.NewDecoder(r.Body).Decode(&role); err != nil { - return nil, nil, NewAppError("GetRoleByName", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetRoleByName", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &role, BuildResponse(r), nil } @@ -6867,7 +6867,7 @@ func (c *Client4) GetRolesByNames(roleNames []string) ([]*Role, *Response, error defer closeBody(r) var list []*Role if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetRolesByNames", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetRolesByNames", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6876,7 +6876,7 @@ func (c *Client4) GetRolesByNames(roleNames []string) ([]*Role, *Response, error func (c *Client4) PatchRole(roleId string, patch *RolePatch) (*Role, *Response, error) { buf, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("PatchRole", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchRole", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.rolesRoute()+fmt.Sprintf("/%v/patch", roleId), buf) if err != nil { @@ -6885,7 +6885,7 @@ func (c *Client4) PatchRole(roleId string, patch *RolePatch) (*Role, *Response, defer closeBody(r) var role Role if err := json.NewDecoder(r.Body).Decode(&role); err != nil { - return nil, nil, NewAppError("PatchRole", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchRole", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &role, BuildResponse(r), nil } @@ -6896,7 +6896,7 @@ func (c *Client4) PatchRole(roleId string, patch *RolePatch) (*Role, *Response, func (c *Client4) CreateScheme(scheme *Scheme) (*Scheme, *Response, error) { buf, err := json.Marshal(scheme) if err != nil { - return nil, nil, NewAppError("CreateScheme", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateScheme", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.schemesRoute(), buf) if err != nil { @@ -6905,7 +6905,7 @@ func (c *Client4) CreateScheme(scheme *Scheme) (*Scheme, *Response, error) { defer closeBody(r) var s Scheme if err := json.NewDecoder(r.Body).Decode(&s); err != nil { - return nil, nil, NewAppError("CreateScheme", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateScheme", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &s, BuildResponse(r), nil } @@ -6919,7 +6919,7 @@ func (c *Client4) GetScheme(id string) (*Scheme, *Response, error) { defer closeBody(r) var s Scheme if err := json.NewDecoder(r.Body).Decode(&s); err != nil { - return nil, nil, NewAppError("GetScheme", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetScheme", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &s, BuildResponse(r), nil } @@ -6933,7 +6933,7 @@ func (c *Client4) GetSchemes(scope string, page int, perPage int) ([]*Scheme, *R defer closeBody(r) var list []*Scheme if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetSchemes", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetSchemes", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6952,7 +6952,7 @@ func (c *Client4) DeleteScheme(id string) (*Response, error) { func (c *Client4) PatchScheme(id string, patch *SchemePatch) (*Scheme, *Response, error) { buf, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("PatchScheme", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchScheme", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.schemeRoute(id)+"/patch", buf) if err != nil { @@ -6961,7 +6961,7 @@ func (c *Client4) PatchScheme(id string, patch *SchemePatch) (*Scheme, *Response defer closeBody(r) var s Scheme if err := json.NewDecoder(r.Body).Decode(&s); err != nil { - return nil, nil, NewAppError("PatchScheme", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchScheme", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &s, BuildResponse(r), nil } @@ -6975,7 +6975,7 @@ func (c *Client4) GetTeamsForScheme(schemeId string, page int, perPage int) ([]* defer closeBody(r) var list []*Team if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetTeamsForScheme", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTeamsForScheme", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -6991,7 +6991,7 @@ func (c *Client4) GetChannelsForScheme(schemeId string, page int, perPage int) ( var ch ChannelList err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelsForScheme", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelsForScheme", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -7053,7 +7053,7 @@ func (c *Client4) uploadPlugin(file io.Reader, force bool) (*Manifest, *Response var m Manifest if err := json.NewDecoder(rp.Body).Decode(&m); err != nil { - return nil, nil, NewAppError("uploadPlugin", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("uploadPlugin", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &m, BuildResponse(rp), nil } @@ -7070,7 +7070,7 @@ func (c *Client4) InstallPluginFromURL(downloadURL string, force bool) (*Manifes var m Manifest if err := json.NewDecoder(r.Body).Decode(&m); err != nil { - return nil, nil, NewAppError("InstallPluginFromUrl", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("InstallPluginFromUrl", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &m, BuildResponse(r), nil } @@ -7079,7 +7079,7 @@ func (c *Client4) InstallPluginFromURL(downloadURL string, force bool) (*Manifes func (c *Client4) InstallMarketplacePlugin(request *InstallMarketplacePluginRequest) (*Manifest, *Response, error) { buf, err := json.Marshal(request) if err != nil { - return nil, nil, NewAppError("InstallMarketplacePlugin", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("InstallMarketplacePlugin", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.pluginsRoute()+"/marketplace", string(buf)) if err != nil { @@ -7089,7 +7089,7 @@ func (c *Client4) InstallMarketplacePlugin(request *InstallMarketplacePluginRequ var m Manifest if err := json.NewDecoder(r.Body).Decode(&m); err != nil { - return nil, nil, NewAppError("InstallMarketplacePlugin", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("InstallMarketplacePlugin", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &m, BuildResponse(r), nil } @@ -7104,7 +7104,7 @@ func (c *Client4) GetPlugins() (*PluginsResponse, *Response, error) { var resp PluginsResponse if err := json.NewDecoder(r.Body).Decode(&resp); err != nil { - return nil, nil, NewAppError("GetPlugins", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPlugins", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &resp, BuildResponse(r), nil } @@ -7119,7 +7119,7 @@ func (c *Client4) GetPluginStatuses() (PluginStatuses, *Response, error) { defer closeBody(r) var list PluginStatuses if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetPluginStatuses", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetPluginStatuses", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -7144,7 +7144,7 @@ func (c *Client4) GetWebappPlugins() ([]*Manifest, *Response, error) { var list []*Manifest if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetWebappPlugins", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetWebappPlugins", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -7187,7 +7187,7 @@ func (c *Client4) GetMarketplacePlugins(filter *MarketplacePluginFilter) ([]*Mar plugins, err := MarketplacePluginsFromReader(r.Body) if err != nil { - return nil, BuildResponse(r), NewAppError(route, "model.client.parse_plugins.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, BuildResponse(r), NewAppError(route, "model.client.parse_plugins.app_error", nil, "", http.StatusBadRequest).Wrap(err) } return plugins, BuildResponse(r), nil @@ -7198,7 +7198,7 @@ func (c *Client4) UpdateChannelScheme(channelId, schemeId string) (*Response, er sip := &SchemeIDPatch{SchemeID: &schemeId} buf, err := json.Marshal(sip) if err != nil { - return nil, NewAppError("UpdateChannelScheme", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("UpdateChannelScheme", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.channelSchemeRoute(channelId), buf) if err != nil { @@ -7213,7 +7213,7 @@ func (c *Client4) UpdateTeamScheme(teamId, schemeId string) (*Response, error) { sip := &SchemeIDPatch{SchemeID: &schemeId} buf, err := json.Marshal(sip) if err != nil { - return nil, NewAppError("UpdateTeamScheme", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("UpdateTeamScheme", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.teamSchemeRoute(teamId), buf) if err != nil { @@ -7266,7 +7266,7 @@ func (c *Client4) GetServerBusy() (*ServerBusyState, *Response, error) { var sbs ServerBusyState if err := json.NewDecoder(r.Body).Decode(&sbs); err != nil { - return nil, nil, NewAppError("GetServerBusy", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetServerBusy", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &sbs, BuildResponse(r), nil } @@ -7293,7 +7293,7 @@ func (c *Client4) GetTermsOfService(etag string) (*TermsOfService, *Response, er defer closeBody(r) var tos TermsOfService if err := json.NewDecoder(r.Body).Decode(&tos); err != nil { - return nil, nil, NewAppError("GetTermsOfService", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetTermsOfService", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &tos, BuildResponse(r), nil } @@ -7308,7 +7308,7 @@ func (c *Client4) GetUserTermsOfService(userId, etag string) (*UserTermsOfServic defer closeBody(r) var u UserTermsOfService if err := json.NewDecoder(r.Body).Decode(&u); err != nil { - return nil, nil, NewAppError("GetUserTermsOfService", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUserTermsOfService", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &u, BuildResponse(r), nil } @@ -7324,7 +7324,7 @@ func (c *Client4) CreateTermsOfService(text, userId string) (*TermsOfService, *R defer closeBody(r) var tos TermsOfService if err := json.NewDecoder(r.Body).Decode(&tos); err != nil { - return nil, nil, NewAppError("CreateTermsOfService", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateTermsOfService", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &tos, BuildResponse(r), nil } @@ -7337,7 +7337,7 @@ func (c *Client4) GetGroup(groupID, etag string) (*Group, *Response, error) { defer closeBody(r) var g Group if err := json.NewDecoder(r.Body).Decode(&g); err != nil { - return nil, nil, NewAppError("GetGroup", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetGroup", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &g, BuildResponse(r), nil } @@ -7345,7 +7345,7 @@ func (c *Client4) GetGroup(groupID, etag string) (*Group, *Response, error) { func (c *Client4) CreateGroup(group *Group) (*Group, *Response, error) { groupJSON, err := json.Marshal(group) if err != nil { - return nil, nil, NewAppError("CreateGroup", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateGroup", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes("/groups", groupJSON) if err != nil { @@ -7354,7 +7354,7 @@ func (c *Client4) CreateGroup(group *Group) (*Group, *Response, error) { defer closeBody(r) var p Group if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("CreateGroup", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateGroup", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -7367,7 +7367,7 @@ func (c *Client4) DeleteGroup(groupID string) (*Group, *Response, error) { defer closeBody(r) var p Group if err := json.NewDecoder(r.Body).Decode(&p); err != nil { - return nil, nil, NewAppError("DeleteGroup", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("DeleteGroup", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &p, BuildResponse(r), nil } @@ -7375,7 +7375,7 @@ func (c *Client4) DeleteGroup(groupID string) (*Group, *Response, error) { func (c *Client4) PatchGroup(groupID string, patch *GroupPatch) (*Group, *Response, error) { payload, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("PatchGroup", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchGroup", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPut(c.groupRoute(groupID)+"/patch", string(payload)) if err != nil { @@ -7384,7 +7384,7 @@ func (c *Client4) PatchGroup(groupID string, patch *GroupPatch) (*Group, *Respon defer closeBody(r) var g Group if err := json.NewDecoder(r.Body).Decode(&g); err != nil { - return nil, nil, NewAppError("PatchGroup", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchGroup", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &g, BuildResponse(r), nil } @@ -7392,7 +7392,7 @@ func (c *Client4) PatchGroup(groupID string, patch *GroupPatch) (*Group, *Respon func (c *Client4) UpsertGroupMembers(groupID string, userIds *GroupModifyMembers) ([]*GroupMember, *Response, error) { payload, err := json.Marshal(userIds) if err != nil { - return nil, nil, NewAppError("UpsertGroupMembers", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpsertGroupMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.groupRoute(groupID)+"/members", payload) if err != nil { @@ -7401,7 +7401,7 @@ func (c *Client4) UpsertGroupMembers(groupID string, userIds *GroupModifyMembers defer closeBody(r) var g []*GroupMember if err := json.NewDecoder(r.Body).Decode(&g); err != nil { - return nil, nil, NewAppError("UpsertGroupMembers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpsertGroupMembers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return g, BuildResponse(r), nil } @@ -7409,7 +7409,7 @@ func (c *Client4) UpsertGroupMembers(groupID string, userIds *GroupModifyMembers func (c *Client4) DeleteGroupMembers(groupID string, userIds *GroupModifyMembers) ([]*GroupMember, *Response, error) { payload, err := json.Marshal(userIds) if err != nil { - return nil, nil, NewAppError("DeleteGroupMembers", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("DeleteGroupMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIDeleteBytes(c.groupRoute(groupID)+"/members", payload) if err != nil { @@ -7418,7 +7418,7 @@ func (c *Client4) DeleteGroupMembers(groupID string, userIds *GroupModifyMembers defer closeBody(r) var g []*GroupMember if err := json.NewDecoder(r.Body).Decode(&g); err != nil { - return nil, nil, NewAppError("DeleteGroupMembers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("DeleteGroupMembers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return g, BuildResponse(r), nil } @@ -7426,7 +7426,7 @@ func (c *Client4) DeleteGroupMembers(groupID string, userIds *GroupModifyMembers func (c *Client4) LinkGroupSyncable(groupID, syncableID string, syncableType GroupSyncableType, patch *GroupSyncablePatch) (*GroupSyncable, *Response, error) { payload, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("LinkGroupSyncable", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("LinkGroupSyncable", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } url := fmt.Sprintf("%s/link", c.groupSyncableRoute(groupID, syncableID, syncableType)) r, err := c.DoAPIPost(url, string(payload)) @@ -7436,7 +7436,7 @@ func (c *Client4) LinkGroupSyncable(groupID, syncableID string, syncableType Gro defer closeBody(r) var gs GroupSyncable if err := json.NewDecoder(r.Body).Decode(&gs); err != nil { - return nil, nil, NewAppError("LinkGroupSyncable", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("LinkGroupSyncable", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &gs, BuildResponse(r), nil } @@ -7459,7 +7459,7 @@ func (c *Client4) GetGroupSyncable(groupID, syncableID string, syncableType Grou defer closeBody(r) var gs GroupSyncable if err := json.NewDecoder(r.Body).Decode(&gs); err != nil { - return nil, nil, NewAppError("GetGroupSyncable", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetGroupSyncable", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &gs, BuildResponse(r), nil } @@ -7472,7 +7472,7 @@ func (c *Client4) GetGroupSyncables(groupID string, syncableType GroupSyncableTy defer closeBody(r) var list []*GroupSyncable if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetGroupSyncables", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetGroupSyncables", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -7480,7 +7480,7 @@ func (c *Client4) GetGroupSyncables(groupID string, syncableType GroupSyncableTy func (c *Client4) PatchGroupSyncable(groupID, syncableID string, syncableType GroupSyncableType, patch *GroupSyncablePatch) (*GroupSyncable, *Response, error) { payload, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("PatchGroupSyncable", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchGroupSyncable", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPut(c.groupSyncableRoute(groupID, syncableID, syncableType)+"/patch", string(payload)) if err != nil { @@ -7489,7 +7489,7 @@ func (c *Client4) PatchGroupSyncable(groupID, syncableID string, syncableType Gr defer closeBody(r) var gs GroupSyncable if err := json.NewDecoder(r.Body).Decode(&gs); err != nil { - return nil, nil, NewAppError("PatchGroupSyncable", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchGroupSyncable", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &gs, BuildResponse(r), nil } @@ -7505,7 +7505,7 @@ func (c *Client4) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, var ugc UsersWithGroupsAndCount if err := json.NewDecoder(r.Body).Decode(&ugc); err != nil { - return nil, 0, nil, NewAppError("TeamMembersMinusGroupMembers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, nil, NewAppError("TeamMembersMinusGroupMembers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ugc.Users, ugc.Count, BuildResponse(r), nil } @@ -7520,7 +7520,7 @@ func (c *Client4) ChannelMembersMinusGroupMembers(channelID string, groupIDs []s defer closeBody(r) var ugc UsersWithGroupsAndCount if err := json.NewDecoder(r.Body).Decode(&ugc); err != nil { - return nil, 0, nil, NewAppError("ChannelMembersMinusGroupMembers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, 0, nil, NewAppError("ChannelMembersMinusGroupMembers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ugc.Users, ugc.Count, BuildResponse(r), nil } @@ -7528,7 +7528,7 @@ func (c *Client4) ChannelMembersMinusGroupMembers(channelID string, groupIDs []s func (c *Client4) PatchConfig(config *Config) (*Config, *Response, error) { buf, err := json.Marshal(config) if err != nil { - return nil, nil, NewAppError("PatchConfig", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchConfig", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.configRoute()+"/patch", buf) if err != nil { @@ -7551,7 +7551,7 @@ func (c *Client4) GetChannelModerations(channelID string, etag string) ([]*Chann var ch []*ChannelModeration err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelModerations", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelModerations", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -7559,7 +7559,7 @@ func (c *Client4) GetChannelModerations(channelID string, etag string) ([]*Chann func (c *Client4) PatchChannelModerations(channelID string, patch []*ChannelModerationPatch) ([]*ChannelModeration, *Response, error) { payload, err := json.Marshal(patch) if err != nil { - return nil, nil, NewAppError("PatchChannelModerations", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("PatchChannelModerations", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPut(c.channelRoute(channelID)+"/moderations/patch", string(payload)) @@ -7571,7 +7571,7 @@ func (c *Client4) PatchChannelModerations(channelID string, patch []*ChannelMode var ch []*ChannelModeration err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("PatchChannelModerations", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("PatchChannelModerations", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -7591,7 +7591,7 @@ func (c *Client4) GetKnownUsers() ([]string, *Response, error) { func (c *Client4) PublishUserTyping(userID string, typingRequest TypingRequest) (*Response, error) { buf, err := json.Marshal(typingRequest) if err != nil { - return nil, NewAppError("PublishUserTyping", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("PublishUserTyping", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.publishUserTypingRoute(userID), buf) if err != nil { @@ -7611,7 +7611,7 @@ func (c *Client4) GetChannelMemberCountsByGroup(channelID string, includeTimezon var ch []*ChannelMemberCountByGroup err = json.NewDecoder(r.Body).Decode(&ch) if err != nil { - return nil, BuildResponse(r), NewAppError("GetChannelMemberCountsByGroup", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("GetChannelMemberCountsByGroup", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return ch, BuildResponse(r), nil } @@ -7620,7 +7620,7 @@ func (c *Client4) GetChannelMemberCountsByGroup(channelID string, includeTimezon func (c *Client4) RequestTrialLicense(users int) (*Response, error) { b, err := json.Marshal(map[string]any{"users": users, "terms_accepted": true}) if err != nil { - return nil, NewAppError("RequestTrialLicense", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("RequestTrialLicense", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost("/trial-license", string(b)) if err != nil { @@ -7639,7 +7639,7 @@ func (c *Client4) GetGroupStats(groupID string) (*GroupStats, *Response, error) defer closeBody(r) var gs GroupStats if err := json.NewDecoder(r.Body).Decode(&gs); err != nil { - return nil, nil, NewAppError("GetGroupStats", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetGroupStats", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &gs, BuildResponse(r), nil } @@ -7654,7 +7654,7 @@ func (c *Client4) GetSidebarCategoriesForTeamForUser(userID, teamID, etag string var cat *OrderedSidebarCategories err = json.NewDecoder(r.Body).Decode(&cat) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.GetSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.GetSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return cat, BuildResponse(r), nil } @@ -7662,7 +7662,7 @@ func (c *Client4) GetSidebarCategoriesForTeamForUser(userID, teamID, etag string func (c *Client4) CreateSidebarCategoryForTeamForUser(userID, teamID string, category *SidebarCategoryWithChannels) (*SidebarCategoryWithChannels, *Response, error) { payload, err := json.Marshal(category) if err != nil { - return nil, nil, NewAppError("CreateSidebarCategoryForTeamForUser", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateSidebarCategoryForTeamForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } route := c.userCategoryRoute(userID, teamID) r, err := c.DoAPIPostBytes(route, payload) @@ -7673,7 +7673,7 @@ func (c *Client4) CreateSidebarCategoryForTeamForUser(userID, teamID string, cat var cat *SidebarCategoryWithChannels err = json.NewDecoder(r.Body).Decode(&cat) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.CreateSidebarCategoryForTeamForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.CreateSidebarCategoryForTeamForUser", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return cat, BuildResponse(r), nil } @@ -7681,7 +7681,7 @@ func (c *Client4) CreateSidebarCategoryForTeamForUser(userID, teamID string, cat func (c *Client4) UpdateSidebarCategoriesForTeamForUser(userID, teamID string, categories []*SidebarCategoryWithChannels) ([]*SidebarCategoryWithChannels, *Response, error) { payload, err := json.Marshal(categories) if err != nil { - return nil, nil, NewAppError("UpdateSidebarCategoriesForTeamForUser", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateSidebarCategoriesForTeamForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } route := c.userCategoryRoute(userID, teamID) @@ -7694,7 +7694,7 @@ func (c *Client4) UpdateSidebarCategoriesForTeamForUser(userID, teamID string, c var cat []*SidebarCategoryWithChannels err = json.NewDecoder(r.Body).Decode(&cat) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.UpdateSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.UpdateSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return cat, BuildResponse(r), nil @@ -7713,7 +7713,7 @@ func (c *Client4) GetSidebarCategoryOrderForTeamForUser(userID, teamID, etag str func (c *Client4) UpdateSidebarCategoryOrderForTeamForUser(userID, teamID string, order []string) ([]string, *Response, error) { payload, err := json.Marshal(order) if err != nil { - return nil, nil, NewAppError("UpdateSidebarCategoryOrderForTeamForUser", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateSidebarCategoryOrderForTeamForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } route := c.userCategoryRoute(userID, teamID) + "/order" r, err := c.DoAPIPutBytes(route, payload) @@ -7734,7 +7734,7 @@ func (c *Client4) GetSidebarCategoryForTeamForUser(userID, teamID, categoryID, e var cat *SidebarCategoryWithChannels err = json.NewDecoder(r.Body).Decode(&cat) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.UpdateSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.UpdateSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return cat, BuildResponse(r), nil @@ -7743,7 +7743,7 @@ func (c *Client4) GetSidebarCategoryForTeamForUser(userID, teamID, categoryID, e func (c *Client4) UpdateSidebarCategoryForTeamForUser(userID, teamID, categoryID string, category *SidebarCategoryWithChannels) (*SidebarCategoryWithChannels, *Response, error) { payload, err := json.Marshal(category) if err != nil { - return nil, nil, NewAppError("UpdateSidebarCategoryForTeamForUser", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateSidebarCategoryForTeamForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } route := c.userCategoryRoute(userID, teamID) + "/" + categoryID r, err := c.DoAPIPutBytes(route, payload) @@ -7754,7 +7754,7 @@ func (c *Client4) UpdateSidebarCategoryForTeamForUser(userID, teamID, categoryID var cat *SidebarCategoryWithChannels err = json.NewDecoder(r.Body).Decode(&cat) if err != nil { - return nil, BuildResponse(r), NewAppError("Client4.UpdateSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode) + return nil, BuildResponse(r), NewAppError("Client4.UpdateSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, "", r.StatusCode).Wrap(err) } return cat, BuildResponse(r), nil @@ -7769,7 +7769,7 @@ func (c *Client4) CheckIntegrity() ([]IntegrityCheckResult, *Response, error) { defer closeBody(r) var results []IntegrityCheckResult if err := json.NewDecoder(r.Body).Decode(&results); err != nil { - return nil, BuildResponse(r), NewAppError("Api4.CheckIntegrity", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, BuildResponse(r), NewAppError("Api4.CheckIntegrity", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return results, BuildResponse(r), nil } @@ -7800,7 +7800,7 @@ func (c *Client4) MarkNoticesViewed(ids []string) (*Response, error) { func (c *Client4) CompleteOnboarding(request *CompleteOnboardingRequest) (*Response, error) { buf, err := json.Marshal(request) if err != nil { - return nil, NewAppError("CompleteOnboarding", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("CompleteOnboarding", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPost(c.systemRoute()+"/onboarding/complete", string(buf)) if err != nil { @@ -7815,7 +7815,7 @@ func (c *Client4) CompleteOnboarding(request *CompleteOnboardingRequest) (*Respo func (c *Client4) CreateUpload(us *UploadSession) (*UploadSession, *Response, error) { buf, err := json.Marshal(us) if err != nil { - return nil, nil, NewAppError("CreateUpload", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateUpload", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.uploadsRoute(), buf) if err != nil { @@ -7825,7 +7825,7 @@ func (c *Client4) CreateUpload(us *UploadSession) (*UploadSession, *Response, er var s UploadSession if err := json.NewDecoder(r.Body).Decode(&s); err != nil { - return nil, nil, NewAppError("CreateUpload", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("CreateUpload", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &s, BuildResponse(r), nil } @@ -7839,7 +7839,7 @@ func (c *Client4) GetUpload(uploadId string) (*UploadSession, *Response, error) defer closeBody(r) var s UploadSession if err := json.NewDecoder(r.Body).Decode(&s); err != nil { - return nil, nil, NewAppError("GetUpload", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUpload", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &s, BuildResponse(r), nil } @@ -7854,7 +7854,7 @@ func (c *Client4) GetUploadsForUser(userId string) ([]*UploadSession, *Response, defer closeBody(r) var list []*UploadSession if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUploadsForUser", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUploadsForUser", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -7873,7 +7873,7 @@ func (c *Client4) UploadData(uploadId string, data io.Reader) (*FileInfo, *Respo return nil, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&fi); err != nil { - return nil, nil, NewAppError("UploadData", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UploadData", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &fi, BuildResponse(r), nil } @@ -7932,7 +7932,7 @@ func (c *Client4) CreateCustomerPayment() (*StripeSetupIntent, *Response, error) func (c *Client4) ConfirmCustomerPayment(confirmRequest *ConfirmPaymentMethodRequest) (*Response, error) { json, err := json.Marshal(confirmRequest) if err != nil { - return nil, NewAppError("ConfirmCustomerPayment", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("ConfirmCustomerPayment", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPostBytes(c.cloudRoute()+"/payment/confirm", json) if err != nil { @@ -7946,7 +7946,7 @@ func (c *Client4) ConfirmCustomerPayment(confirmRequest *ConfirmPaymentMethodReq func (c *Client4) RequestCloudTrial(email *StartCloudTrialRequest) (*Subscription, *Response, error) { payload, err := json.Marshal(email) if err != nil { - return nil, nil, NewAppError("RequestCloudTrial", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("RequestCloudTrial", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.cloudRoute()+"/request-trial", payload) if err != nil { @@ -8039,7 +8039,7 @@ func (c *Client4) GetInvoicesForSubscription() ([]*Invoice, *Response, error) { func (c *Client4) UpdateCloudCustomer(customerInfo *CloudCustomerInfo) (*CloudCustomer, *Response, error) { customerBytes, err := json.Marshal(customerInfo) if err != nil { - return nil, nil, NewAppError("UpdateCloudCustomer", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateCloudCustomer", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.cloudRoute()+"/customer", customerBytes) if err != nil { @@ -8056,7 +8056,7 @@ func (c *Client4) UpdateCloudCustomer(customerInfo *CloudCustomerInfo) (*CloudCu func (c *Client4) UpdateCloudCustomerAddress(address *Address) (*CloudCustomer, *Response, error) { addressBytes, err := json.Marshal(address) if err != nil { - return nil, nil, NewAppError("UpdateCloudCustomerAddress", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("UpdateCloudCustomerAddress", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } r, err := c.DoAPIPutBytes(c.cloudRoute()+"/customer/address", addressBytes) if err != nil { @@ -8111,7 +8111,7 @@ func (c *Client4) DownloadExport(name string, wr io.Writer, offset int64) (int64 defer closeBody(r) n, err := io.Copy(wr, r.Body) if err != nil { - return n, BuildResponse(r), NewAppError("DownloadExport", "model.client.copy.app_error", nil, err.Error(), r.StatusCode) + return n, BuildResponse(r), NewAppError("DownloadExport", "model.client.copy.app_error", nil, "", r.StatusCode).Wrap(err) } return n, BuildResponse(r), nil } @@ -8282,7 +8282,7 @@ func (c *Client4) GetUsersWithInvalidEmails(page, perPage int) ([]*User, *Respon return list, BuildResponse(r), nil } if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } @@ -8295,7 +8295,7 @@ func (c *Client4) GetAppliedSchemaMigrations() ([]AppliedMigration, *Response, e defer closeBody(r) var list []AppliedMigration if err := json.NewDecoder(r.Body).Decode(&list); err != nil { - return nil, nil, NewAppError("GetUsers", "api.unmarshal_error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, NewAppError("GetUsers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err) } return list, BuildResponse(r), nil } diff --git a/model/command.go b/model/command.go index 9742812f94..4d4bb3bb80 100644 --- a/model/command.go +++ b/model/command.go @@ -122,7 +122,7 @@ func (o *Command) IsValid() *AppError { if o.AutocompleteData != nil { if err := o.AutocompleteData.IsValid(); err != nil { - return NewAppError("Command.IsValid", "model.command.is_valid.autocomplete_data.app_error", nil, err.Error(), http.StatusBadRequest) + return NewAppError("Command.IsValid", "model.command.is_valid.autocomplete_data.app_error", nil, "", http.StatusBadRequest).Wrap(err) } } diff --git a/model/config.go b/model/config.go index 8d1119a49d..c9e2c865b9 100644 --- a/model/config.go +++ b/model/config.go @@ -3078,19 +3078,20 @@ const ConfigAccessTagAnySysConsoleRead = "*_read" // environment with ExperimentalSettings.RestrictedSystemAdmin set to true. // // Example: -// type HairSettings struct { -// // Colour is writeable with either PermissionSysconsoleWriteReporting or PermissionSysconsoleWriteUserManagementGroups. -// // It is readable by PermissionSysconsoleReadReporting and PermissionSysconsoleReadUserManagementGroups permissions. -// // PermissionManageSystem grants read and write access. -// Colour string `access:"reporting,user_management_groups"` // -// // Length is only readable and writable via PermissionManageSystem. -// Length string +// type HairSettings struct { +// // Colour is writeable with either PermissionSysconsoleWriteReporting or PermissionSysconsoleWriteUserManagementGroups. +// // It is readable by PermissionSysconsoleReadReporting and PermissionSysconsoleReadUserManagementGroups permissions. +// // PermissionManageSystem grants read and write access. +// Colour string `access:"reporting,user_management_groups"` // -// // Product is only writeable by PermissionManageSystem if ExperimentalSettings.RestrictSystemAdmin is false. -// // PermissionManageSystem can always read the value. -// Product bool `access:write_restrictable` -// } +// // Length is only readable and writable via PermissionManageSystem. +// Length string +// +// // Product is only writeable by PermissionManageSystem if ExperimentalSettings.RestrictSystemAdmin is false. +// // PermissionManageSystem can always read the value. +// Product bool `access:write_restrictable` +// } type Config struct { ServiceSettings ServiceSettings TeamSettings TeamSettings @@ -3500,19 +3501,19 @@ func (s *LdapSettings) isValid() *AppError { if *s.UserFilter != "" { if _, err := ldap.CompileFilter(*s.UserFilter); err != nil { - return NewAppError("ValidateFilter", "ent.ldap.validate_filter.app_error", nil, err.Error(), http.StatusBadRequest) + return NewAppError("ValidateFilter", "ent.ldap.validate_filter.app_error", nil, "", http.StatusBadRequest).Wrap(err) } } if *s.GuestFilter != "" { if _, err := ldap.CompileFilter(*s.GuestFilter); err != nil { - return NewAppError("LdapSettings.isValid", "ent.ldap.validate_guest_filter.app_error", nil, err.Error(), http.StatusBadRequest) + return NewAppError("LdapSettings.isValid", "ent.ldap.validate_guest_filter.app_error", nil, "", http.StatusBadRequest).Wrap(err) } } if *s.AdminFilter != "" { if _, err := ldap.CompileFilter(*s.AdminFilter); err != nil { - return NewAppError("LdapSettings.isValid", "ent.ldap.validate_admin_filter.app_error", nil, err.Error(), http.StatusBadRequest) + return NewAppError("LdapSettings.isValid", "ent.ldap.validate_admin_filter.app_error", nil, "", http.StatusBadRequest).Wrap(err) } } } @@ -3644,13 +3645,13 @@ func (s *ServiceSettings) isValid() *AppError { if *s.SiteURL != "" { if _, err := url.ParseRequestURI(*s.SiteURL); err != nil { - return NewAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, err.Error(), http.StatusBadRequest) + return NewAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, "", http.StatusBadRequest).Wrap(err) } } if *s.WebsocketURL != "" { if _, err := url.ParseRequestURI(*s.WebsocketURL); err != nil { - return NewAppError("Config.IsValid", "model.config.is_valid.websocket_url.app_error", nil, err.Error(), http.StatusBadRequest) + return NewAppError("Config.IsValid", "model.config.is_valid.websocket_url.app_error", nil, "", http.StatusBadRequest).Wrap(err) } } @@ -3706,7 +3707,7 @@ func (s *ElasticsearchSettings) isValid() *AppError { } if _, err := time.Parse("15:04", *s.PostsAggregatorJobStartTime); err != nil { - return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.posts_aggregator_job_start_time.app_error", nil, err.Error(), http.StatusBadRequest) + return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.posts_aggregator_job_start_time.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if *s.LiveIndexingBatchSize < 1 { @@ -3756,7 +3757,7 @@ func (s *DataRetentionSettings) isValid() *AppError { } if _, err := time.Parse("15:04", *s.DeletionJobStartTime); err != nil { - return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.deletion_job_start_time.app_error", nil, err.Error(), http.StatusBadRequest) + return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.deletion_job_start_time.app_error", nil, "", http.StatusBadRequest).Wrap(err) } return nil @@ -3782,7 +3783,7 @@ func (s *MessageExportSettings) isValid() *AppError { } else if s.DailyRunTime == nil { return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, "", http.StatusBadRequest) } else if _, err := time.Parse("15:04", *s.DailyRunTime); err != nil { - return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, err.Error(), http.StatusBadRequest) + return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, "", http.StatusBadRequest).Wrap(err) } else if s.BatchSize == nil || *s.BatchSize < 0 { return NewAppError("Config.IsValid", "model.config.is_valid.message_export.batch_size.app_error", nil, "", http.StatusBadRequest) } else if s.ExportFormat == nil || (*s.ExportFormat != ComplianceExportTypeActiance && *s.ExportFormat != ComplianceExportTypeGlobalrelay && *s.ExportFormat != ComplianceExportTypeCsv) { diff --git a/model/file_info.go b/model/file_info.go index f42d1fbc54..f6ae41ab36 100644 --- a/model/file_info.go +++ b/model/file_info.go @@ -161,7 +161,7 @@ func GetInfoForBytes(name string, data io.ReadSeeker, size int) (*FileInfo, *App if err != nil { // Still return the rest of the info even though it doesn't appear to be an actual gif info.HasPreviewImage = true - return info, NewAppError("GetInfoForBytes", "model.file_info.get.gif.app_error", nil, err.Error(), http.StatusBadRequest) + return info, NewAppError("GetInfoForBytes", "model.file_info.get.gif.app_error", nil, "", http.StatusBadRequest).Wrap(err) } info.HasPreviewImage = frameCount == 1 } else { diff --git a/model/incoming_webhook.go b/model/incoming_webhook.go index cd020c90dc..bfd314d577 100644 --- a/model/incoming_webhook.go +++ b/model/incoming_webhook.go @@ -123,22 +123,24 @@ func (o *IncomingWebhook) PreUpdate() { // try to handle that. An example invalid JSON string from an incoming webhook // might look like this (strings for both "text" and "fallback" attributes are // invalid JSON strings because they contain unescaped newlines and tabs): -// `{ -// "text": "this is a test -// that contains a newline and tabs", -// "attachments": [ -// { -// "fallback": "Required plain-text summary of the attachment -// that contains a newline and tabs", -// "color": "#36a64f", -// ... -// "text": "Optional text that appears within the attachment -// that contains a newline and tabs", -// ... -// "thumb_url": "http://example.com/path/to/thumb.png" -// } -// ] -// }` +// +// `{ +// "text": "this is a test +// that contains a newline and tabs", +// "attachments": [ +// { +// "fallback": "Required plain-text summary of the attachment +// that contains a newline and tabs", +// "color": "#36a64f", +// ... +// "text": "Optional text that appears within the attachment +// that contains a newline and tabs", +// ... +// "thumb_url": "http://example.com/path/to/thumb.png" +// } +// ] +// }` +// // This function will search for `"key": "value"` pairs, and escape \n, \t // from the value. func escapeControlCharsFromPayload(by []byte) []byte { @@ -191,7 +193,7 @@ func IncomingWebhookRequestFromJSON(data io.Reader) (*IncomingWebhookRequest, *A if err != nil { o, err = decodeIncomingWebhookRequest(escapeControlCharsFromPayload(by)) if err != nil { - return nil, NewAppError("IncomingWebhookRequestFromJSON", "model.incoming_hook.parse_data.app_error", nil, err.Error(), http.StatusBadRequest) + return nil, NewAppError("IncomingWebhookRequestFromJSON", "model.incoming_hook.parse_data.app_error", nil, "", http.StatusBadRequest).Wrap(err) } } diff --git a/model/integration_action.go b/model/integration_action.go index c45f28284c..353ebe5559 100644 --- a/model/integration_action.go +++ b/model/integration_action.go @@ -261,7 +261,7 @@ func GenerateTriggerId(userId string, s crypto.Signer) (string, string, *AppErro sum.Write([]byte(triggerData)) signature, err := s.Sign(rand.Reader, sum.Sum(nil), h) if err != nil { - return "", "", NewAppError("GenerateTriggerId", "interactive_message.generate_trigger_id.signing_failed", nil, err.Error(), http.StatusInternalServerError) + return "", "", NewAppError("GenerateTriggerId", "interactive_message.generate_trigger_id.signing_failed", nil, "", http.StatusInternalServerError).Wrap(err) } base64Sig := base64.StdEncoding.EncodeToString(signature) @@ -283,7 +283,7 @@ func (r *PostActionIntegrationRequest) GenerateTriggerId(s crypto.Signer) (strin func DecodeAndVerifyTriggerId(triggerId string, s *ecdsa.PrivateKey) (string, string, *AppError) { triggerIdBytes, err := base64.StdEncoding.DecodeString(triggerId) if err != nil { - return "", "", NewAppError("DecodeAndVerifyTriggerId", "interactive_message.decode_trigger_id.base64_decode_failed", nil, err.Error(), http.StatusBadRequest) + return "", "", NewAppError("DecodeAndVerifyTriggerId", "interactive_message.decode_trigger_id.base64_decode_failed", nil, "", http.StatusBadRequest).Wrap(err) } split := strings.Split(string(triggerIdBytes), ":") @@ -303,7 +303,7 @@ func DecodeAndVerifyTriggerId(triggerId string, s *ecdsa.PrivateKey) (string, st signature, err := base64.StdEncoding.DecodeString(split[3]) if err != nil { - return "", "", NewAppError("DecodeAndVerifyTriggerId", "interactive_message.decode_trigger_id.base64_decode_failed_signature", nil, err.Error(), http.StatusBadRequest) + return "", "", NewAppError("DecodeAndVerifyTriggerId", "interactive_message.decode_trigger_id.base64_decode_failed_signature", nil, "", http.StatusBadRequest).Wrap(err) } var esig struct { @@ -311,7 +311,7 @@ func DecodeAndVerifyTriggerId(triggerId string, s *ecdsa.PrivateKey) (string, st } if _, err := asn1.Unmarshal(signature, &esig); err != nil { - return "", "", NewAppError("DecodeAndVerifyTriggerId", "interactive_message.decode_trigger_id.signature_decode_failed", nil, err.Error(), http.StatusBadRequest) + return "", "", NewAppError("DecodeAndVerifyTriggerId", "interactive_message.decode_trigger_id.signature_decode_failed", nil, "", http.StatusBadRequest).Wrap(err) } triggerData := strings.Join([]string{clientTriggerId, userId, timestampStr}, ":") + ":" diff --git a/model/upload_session.go b/model/upload_session.go index 0fb54ce6b5..4dacb53013 100644 --- a/model/upload_session.go +++ b/model/upload_session.go @@ -79,7 +79,7 @@ func (us *UploadSession) IsValid() *AppError { } if err := us.Type.IsValid(); err != nil { - return NewAppError("UploadSession.IsValid", "model.upload_session.is_valid.type.app_error", nil, err.Error(), http.StatusBadRequest) + return NewAppError("UploadSession.IsValid", "model.upload_session.is_valid.type.app_error", nil, "", http.StatusBadRequest).Wrap(err) } if !IsValidId(us.UserId) && us.UserId != UploadNoUserID { diff --git a/model/user.go b/model/user.go index 59d0110cb4..d3ec889ce8 100644 --- a/model/user.go +++ b/model/user.go @@ -381,7 +381,7 @@ func (u *User) IsValid() *AppError { if len(u.Timezone) > 0 { if tzJSON, err := json.Marshal(u.Timezone); err != nil { - return NewAppError("User.IsValid", "model.user.is_valid.marshal.app_error", nil, err.Error(), http.StatusInternalServerError) + return NewAppError("User.IsValid", "model.user.is_valid.marshal.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } else if utf8.RuneCount(tzJSON) > UserTimezoneMaxRunes { return InvalidUserError("timezone_limit", u.Id) } diff --git a/model/utils.go b/model/utils.go index 86ec1536f2..968d0f9c3d 100644 --- a/model/utils.go +++ b/model/utils.go @@ -234,12 +234,11 @@ func (er *AppError) Error() string { sb.WriteString(er.DetailedError) } - // render all wrapped errors + // render the wrapped error err := er.wrapped - for err != nil { + if err != nil { sb.WriteString(", ") sb.WriteString(err.Error()) - err = errors.Unwrap(err) } return sb.String() diff --git a/model/utils_test.go b/model/utils_test.go index 9ac33e39c1..e02c38dc1f 100644 --- a/model/utils_test.go +++ b/model/utils_test.go @@ -103,12 +103,12 @@ func TestAppErrorRender(t *testing.T) { t.Run("WrappedMultiple", func(t *testing.T) { aerr := NewAppError("here", "message", nil, "", http.StatusTeapot).Wrap(fmt.Errorf("my error (%w)", fmt.Errorf("inner error"))) - assert.EqualError(t, aerr, "here: message, my error (inner error), inner error") + assert.EqualError(t, aerr, "here: message, my error (inner error)") }) t.Run("DetailedWrappedMultiple", func(t *testing.T) { aerr := NewAppError("here", "message", nil, "details", http.StatusTeapot).Wrap(fmt.Errorf("my error (%w)", fmt.Errorf("inner error"))) - assert.EqualError(t, aerr, "here: message, details, my error (inner error), inner error") + assert.EqualError(t, aerr, "here: message, details, my error (inner error)") }) } diff --git a/model/websocket_client.go b/model/websocket_client.go index bd9faa9c4c..0693a24786 100644 --- a/model/websocket_client.go +++ b/model/websocket_client.go @@ -89,7 +89,7 @@ func NewWebSocketClientWithDialer(dialer *websocket.Dialer, url, authToken strin func makeClient(dialer *websocket.Dialer, url, connectURL, authToken string, header http.Header) (*WebSocketClient, error) { conn, _, err := dialer.Dial(connectURL, header) if err != nil { - return nil, NewAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, NewAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } client := &WebSocketClient{ @@ -140,7 +140,7 @@ func (wsc *WebSocketClient) ConnectWithDialer(dialer *websocket.Dialer) *AppErro var err error wsc.Conn, _, err = dialer.Dial(wsc.ConnectURL, nil) if err != nil { - return NewAppError("Connect", "model.websocket_client.connect_fail.app_error", nil, err.Error(), http.StatusInternalServerError) + return NewAppError("Connect", "model.websocket_client.connect_fail.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } // Super racy and should not be done anyways. // All of this needs to be redesigned for v6. @@ -235,7 +235,7 @@ func (wsc *WebSocketClient) Listen() { _, r, err := wsc.Conn.NextReader() if err != nil { if !websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) { - wsc.ListenError = NewAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, err.Error(), http.StatusInternalServerError) + wsc.ListenError = NewAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } return } @@ -245,7 +245,7 @@ func (wsc *WebSocketClient) Listen() { // This should use a different error ID, but en.json is not imported anyways. // It's a different bug altogether but we let it be for now. // See MM-24520. - wsc.ListenError = NewAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, err.Error(), http.StatusInternalServerError) + wsc.ListenError = NewAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, "", http.StatusInternalServerError).Wrap(err) return } diff --git a/services/searchengine/bleveengine/bleve.go b/services/searchengine/bleveengine/bleve.go index 5a43a712ed..2d0d57d397 100644 --- a/services/searchengine/bleveengine/bleve.go +++ b/services/searchengine/bleveengine/bleve.go @@ -152,22 +152,22 @@ func (b *BleveEngine) openIndexes() *model.AppError { var err error b.PostIndex, err = b.createOrOpenIndex(PostIndex, getPostIndexMapping()) if err != nil { - return model.NewAppError("Bleveengine.Start", "bleveengine.create_post_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.Start", "bleveengine.create_post_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } b.FileIndex, err = b.createOrOpenIndex(FileIndex, getFileIndexMapping()) if err != nil { - return model.NewAppError("Bleveengine.Start", "bleveengine.create_file_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.Start", "bleveengine.create_file_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } b.UserIndex, err = b.createOrOpenIndex(UserIndex, getUserIndexMapping()) if err != nil { - return model.NewAppError("Bleveengine.Start", "bleveengine.create_user_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.Start", "bleveengine.create_user_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } b.ChannelIndex, err = b.createOrOpenIndex(ChannelIndex, getChannelIndexMapping()) if err != nil { - return model.NewAppError("Bleveengine.Start", "bleveengine.create_channel_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.Start", "bleveengine.create_channel_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } atomic.StoreInt32(&b.ready, 1) @@ -190,19 +190,19 @@ func (b *BleveEngine) Start() *model.AppError { func (b *BleveEngine) closeIndexes() *model.AppError { if b.IsActive() { if err := b.PostIndex.Close(); err != nil { - return model.NewAppError("Bleveengine.Stop", "bleveengine.stop_post_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.Stop", "bleveengine.stop_post_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := b.FileIndex.Close(); err != nil { - return model.NewAppError("Bleveengine.Stop", "bleveengine.stop_file_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.Stop", "bleveengine.stop_file_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := b.UserIndex.Close(); err != nil { - return model.NewAppError("Bleveengine.Stop", "bleveengine.stop_user_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.Stop", "bleveengine.stop_user_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := b.ChannelIndex.Close(); err != nil { - return model.NewAppError("Bleveengine.Stop", "bleveengine.stop_channel_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.Stop", "bleveengine.stop_channel_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } } @@ -253,16 +253,16 @@ func (b *BleveEngine) TestConfig(cfg *model.Config) *model.AppError { func (b *BleveEngine) deleteIndexes() *model.AppError { if err := os.RemoveAll(b.getIndexDir(PostIndex)); err != nil { - return model.NewAppError("Bleveengine.PurgeIndexes", "bleveengine.purge_post_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.PurgeIndexes", "bleveengine.purge_post_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := os.RemoveAll(b.getIndexDir(UserIndex)); err != nil { - return model.NewAppError("Bleveengine.PurgeIndexes", "bleveengine.purge_user_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.PurgeIndexes", "bleveengine.purge_user_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := os.RemoveAll(b.getIndexDir(ChannelIndex)); err != nil { - return model.NewAppError("Bleveengine.PurgeIndexes", "bleveengine.purge_channel_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.PurgeIndexes", "bleveengine.purge_channel_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } if err := os.RemoveAll(b.getIndexDir(FileIndex)); err != nil { - return model.NewAppError("Bleveengine.PurgeIndexes", "bleveengine.purge_file_index.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.PurgeIndexes", "bleveengine.purge_file_index.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } diff --git a/services/searchengine/bleveengine/indexer/indexing_job.go b/services/searchengine/bleveengine/indexer/indexing_job.go index 155167abb4..909feacff3 100644 --- a/services/searchengine/bleveengine/indexer/indexing_job.go +++ b/services/searchengine/bleveengine/indexer/indexing_job.go @@ -161,7 +161,7 @@ func (worker *BleveIndexerWorker) DoJob(job *model.Job) { startInt, err := strconv.ParseInt(startString, 10, 64) if err != nil { mlog.Error("Worker: Failed to parse start_time for job", mlog.String("workername", worker.name), mlog.String("start_time", startString), mlog.String("job_id", job.Id), mlog.Err(err)) - appError := model.NewAppError("BleveIndexerWorker", "bleveengine.indexer.do_job.parse_start_time.error", nil, err.Error(), http.StatusInternalServerError) + appError := model.NewAppError("BleveIndexerWorker", "bleveengine.indexer.do_job.parse_start_time.error", nil, "", http.StatusInternalServerError).Wrap(err) if err := worker.jobServer.SetJobError(job, appError); err != nil { mlog.Error("Worker: Failed to set job error", mlog.String("workername", worker.name), mlog.String("job_id", job.Id), mlog.Err(err), mlog.NamedErr("set_error", appError)) } @@ -174,7 +174,7 @@ func (worker *BleveIndexerWorker) DoJob(job *model.Job) { oldestEntityCreationTime, err := worker.jobServer.Store.Post().GetOldestEntityCreationTime() if err != nil { mlog.Error("Worker: Failed to fetch oldest entity for job.", mlog.String("workername", worker.name), mlog.String("job_id", job.Id), mlog.String("start_time", startString), mlog.Err(err)) - appError := model.NewAppError("BleveIndexerWorker", "bleveengine.indexer.do_job.get_oldest_entity.error", nil, err.Error(), http.StatusInternalServerError) + appError := model.NewAppError("BleveIndexerWorker", "bleveengine.indexer.do_job.get_oldest_entity.error", nil, "", http.StatusInternalServerError).Wrap(err) if err := worker.jobServer.SetJobError(job, appError); err != nil { mlog.Error("Worker: Failed to set job error", mlog.String("workername", worker.name), mlog.String("job_id", job.Id), mlog.Err(err), mlog.NamedErr("set_error", appError)) } @@ -188,7 +188,7 @@ func (worker *BleveIndexerWorker) DoJob(job *model.Job) { endInt, err := strconv.ParseInt(endString, 10, 64) if err != nil { mlog.Error("Worker: Failed to parse end_time for job", mlog.String("workername", worker.name), mlog.String("job_id", job.Id), mlog.String("end_time", endString), mlog.Err(err)) - appError := model.NewAppError("BleveIndexerWorker", "bleveengine.indexer.do_job.parse_end_time.error", nil, err.Error(), http.StatusInternalServerError) + appError := model.NewAppError("BleveIndexerWorker", "bleveengine.indexer.do_job.parse_end_time.error", nil, "", http.StatusInternalServerError).Wrap(err) if err := worker.jobServer.SetJobError(job, appError); err != nil { mlog.Error("Worker: Failed to set job errorv", mlog.String("workername", worker.name), mlog.String("job_id", job.Id), mlog.Err(err), mlog.NamedErr("set_error", appError)) } @@ -339,7 +339,7 @@ func (worker *BleveIndexerWorker) IndexPostsBatch(progress IndexingProgress) (In posts, err = worker.jobServer.Store.Post().GetPostsBatchForIndexing(progress.LastEntityTime, progress.LastPostID, *worker.jobServer.Config().BleveSettings.BatchSize) if err != nil { if tries >= 10 { - return progress, model.NewAppError("IndexPostsBatch", "app.post.get_posts_batch_for_indexing.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return progress, model.NewAppError("IndexPostsBatch", "app.post.get_posts_batch_for_indexing.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } mlog.Warn("Failed to get posts batch for indexing. Retrying.", mlog.Err(err)) @@ -393,7 +393,7 @@ func (worker *BleveIndexerWorker) BulkIndexPosts(posts []*model.PostForIndexing, defer worker.engine.Mutex.RUnlock() if err := worker.engine.PostIndex.Batch(batch); err != nil { - return nil, model.NewAppError("BleveIndexerWorker.BulkIndexPosts", "bleveengine.indexer.do_job.bulk_index_posts.batch_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("BleveIndexerWorker.BulkIndexPosts", "bleveengine.indexer.do_job.bulk_index_posts.batch_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &posts[len(posts)-1].Post, nil } @@ -407,7 +407,7 @@ func (worker *BleveIndexerWorker) IndexFilesBatch(progress IndexingProgress) (In files, err = worker.jobServer.Store.FileInfo().GetFilesBatchForIndexing(progress.LastEntityTime, progress.LastFileID, *worker.jobServer.Config().BleveSettings.BatchSize) if err != nil { if tries >= 10 { - return progress, model.NewAppError("IndexFilesBatch", "app.post.get_files_batch_for_indexing.get.app_error", nil, err.Error(), http.StatusInternalServerError) + return progress, model.NewAppError("IndexFilesBatch", "app.post.get_files_batch_for_indexing.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } mlog.Warn("Failed to get files batch for indexing. Retrying.", mlog.Err(err)) @@ -460,7 +460,7 @@ func (worker *BleveIndexerWorker) BulkIndexFiles(files []*model.FileForIndexing, defer worker.engine.Mutex.RUnlock() if err := worker.engine.FileIndex.Batch(batch); err != nil { - return nil, model.NewAppError("BleveIndexerWorker.BulkIndexPosts", "bleveengine.indexer.do_job.bulk_index_files.batch_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("BleveIndexerWorker.BulkIndexPosts", "bleveengine.indexer.do_job.bulk_index_files.batch_error", nil, "", http.StatusInternalServerError).Wrap(err) } return &files[len(files)-1].FileInfo, nil } @@ -474,7 +474,7 @@ func (worker *BleveIndexerWorker) IndexChannelsBatch(progress IndexingProgress) channels, nErr = worker.jobServer.Store.Channel().GetChannelsBatchForIndexing(progress.LastEntityTime, progress.LastChannelID, *worker.jobServer.Config().BleveSettings.BatchSize) if nErr != nil { if tries >= 10 { - return progress, model.NewAppError("BleveIndexerWorker.IndexChannelsBatch", "app.channel.get_channels_batch_for_indexing.get.app_error", nil, nErr.Error(), http.StatusInternalServerError) + return progress, model.NewAppError("BleveIndexerWorker.IndexChannelsBatch", "app.channel.get_channels_batch_for_indexing.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) } mlog.Warn("Failed to get channels batch for indexing. Retrying.", mlog.Err(nErr)) @@ -521,14 +521,14 @@ func (worker *BleveIndexerWorker) BulkIndexChannels(channels []*model.Channel, p if channel.Type == model.ChannelTypePrivate { userIDs, err = worker.jobServer.Store.Channel().GetAllChannelMembersById(channel.Id) if err != nil { - return nil, model.NewAppError("BleveIndexerWorker.BulkIndexChannels", "bleveengine.indexer.do_job.bulk_index_channels.batch_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("BleveIndexerWorker.BulkIndexChannels", "bleveengine.indexer.do_job.bulk_index_channels.batch_error", nil, "", http.StatusInternalServerError).Wrap(err) } } // Get teamMember ids from channelid teamMemberIDs, err := worker.jobServer.Store.Channel().GetTeamMembersForChannel(channel.Id) if err != nil { - return nil, model.NewAppError("BleveIndexerWorker.BulkIndexChannels", "bleveengine.indexer.do_job.bulk_index_channels.batch_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("BleveIndexerWorker.BulkIndexChannels", "bleveengine.indexer.do_job.bulk_index_channels.batch_error", nil, "", http.StatusInternalServerError).Wrap(err) } searchChannel := bleveengine.BLVChannelFromChannel(channel, userIDs, teamMemberIDs) @@ -542,7 +542,7 @@ func (worker *BleveIndexerWorker) BulkIndexChannels(channels []*model.Channel, p defer worker.engine.Mutex.RUnlock() if err := worker.engine.ChannelIndex.Batch(batch); err != nil { - return nil, model.NewAppError("BleveIndexerWorker.BulkIndexChannels", "bleveengine.indexer.do_job.bulk_index_channels.batch_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("BleveIndexerWorker.BulkIndexChannels", "bleveengine.indexer.do_job.bulk_index_channels.batch_error", nil, "", http.StatusInternalServerError).Wrap(err) } return channels[len(channels)-1], nil } @@ -554,7 +554,7 @@ func (worker *BleveIndexerWorker) IndexUsersBatch(progress IndexingProgress) (In for users == nil { if usersBatch, err := worker.jobServer.Store.User().GetUsersBatchForIndexing(progress.LastEntityTime, progress.LastUserID, *worker.jobServer.Config().BleveSettings.BatchSize); err != nil { if tries >= 10 { - return progress, model.NewAppError("IndexUsersBatch", "app.user.get_users_batch_for_indexing.get_users.app_error", nil, err.Error(), http.StatusInternalServerError) + return progress, model.NewAppError("IndexUsersBatch", "app.user.get_users_batch_for_indexing.get_users.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } mlog.Warn("Failed to get users batch for indexing. Retrying.", mlog.Err(err)) @@ -608,7 +608,7 @@ func (worker *BleveIndexerWorker) BulkIndexUsers(users []*model.UserForIndexing, defer worker.engine.Mutex.RUnlock() if err := worker.engine.UserIndex.Batch(batch); err != nil { - return nil, model.NewAppError("BleveIndexerWorker.BulkIndexUsers", "bleveengine.indexer.do_job.bulk_index_users.batch_error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("BleveIndexerWorker.BulkIndexUsers", "bleveengine.indexer.do_job.bulk_index_users.batch_error", nil, "", http.StatusInternalServerError).Wrap(err) } return users[len(users)-1], nil } diff --git a/services/searchengine/bleveengine/search.go b/services/searchengine/bleveengine/search.go index 4e33613274..2a11539f9f 100644 --- a/services/searchengine/bleveengine/search.go +++ b/services/searchengine/bleveengine/search.go @@ -23,7 +23,7 @@ func (b *BleveEngine) IndexPost(post *model.Post, teamId string) *model.AppError blvPost := BLVPostFromPost(post, teamId) if err := b.PostIndex.Index(blvPost.Id, blvPost); err != nil { - return model.NewAppError("Bleveengine.IndexPost", "bleveengine.index_post.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.IndexPost", "bleveengine.index_post.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } @@ -214,7 +214,7 @@ func (b *BleveEngine) SearchPosts(channels model.ChannelList, searchParams []*mo search.SortBy([]string{"-CreateAt"}) results, err := b.PostIndex.Search(search) if err != nil { - return nil, nil, model.NewAppError("Bleveengine.SearchPosts", "bleveengine.search_posts.error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("Bleveengine.SearchPosts", "bleveengine.search_posts.error", nil, "", http.StatusInternalServerError).Wrap(err) } postIds := []string{} @@ -298,7 +298,7 @@ func (b *BleveEngine) DeletePost(post *model.Post) *model.AppError { defer b.Mutex.RUnlock() if err := b.PostIndex.Delete(post.Id); err != nil { - return model.NewAppError("Bleveengine.DeletePost", "bleveengine.delete_post.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.DeletePost", "bleveengine.delete_post.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } @@ -309,7 +309,7 @@ func (b *BleveEngine) IndexChannel(channel *model.Channel, userIDs, teamMemberID blvChannel := BLVChannelFromChannel(channel, userIDs, teamMemberIDs) if err := b.ChannelIndex.Index(blvChannel.Id, blvChannel); err != nil { - return model.NewAppError("Bleveengine.IndexChannel", "bleveengine.index_channel.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.IndexChannel", "bleveengine.index_channel.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } @@ -381,7 +381,7 @@ func (b *BleveEngine) SearchChannels(teamId, userID, term string, isGuest bool) query.Size = model.ChannelSearchDefaultLimit results, err := b.ChannelIndex.Search(query) if err != nil { - return nil, model.NewAppError("Bleveengine.SearchChannels", "bleveengine.search_channels.error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("Bleveengine.SearchChannels", "bleveengine.search_channels.error", nil, "", http.StatusInternalServerError).Wrap(err) } channelIds := []string{} @@ -397,7 +397,7 @@ func (b *BleveEngine) DeleteChannel(channel *model.Channel) *model.AppError { defer b.Mutex.RUnlock() if err := b.ChannelIndex.Delete(channel.Id); err != nil { - return model.NewAppError("Bleveengine.DeleteChannel", "bleveengine.delete_channel.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.DeleteChannel", "bleveengine.delete_channel.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } @@ -408,7 +408,7 @@ func (b *BleveEngine) IndexUser(user *model.User, teamsIds, channelsIds []string blvUser := BLVUserFromUserAndTeams(user, teamsIds, channelsIds) if err := b.UserIndex.Index(blvUser.Id, blvUser); err != nil { - return model.NewAppError("Bleveengine.IndexUser", "bleveengine.index_user.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.IndexUser", "bleveengine.index_user.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } @@ -440,7 +440,7 @@ func (b *BleveEngine) SearchUsersInChannel(teamId, channelId string, restrictedT uchanSearch.Size = options.Limit uchan, err := b.UserIndex.Search(uchanSearch) if err != nil { - return nil, nil, model.NewAppError("Bleveengine.SearchUsersInChannel", "bleveengine.search_users_in_channel.uchan.error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("Bleveengine.SearchUsersInChannel", "bleveengine.search_users_in_channel.uchan.error", nil, "", http.StatusInternalServerError).Wrap(err) } // users not in channel @@ -477,7 +477,7 @@ func (b *BleveEngine) SearchUsersInChannel(teamId, channelId string, restrictedT nuchanSearch.Size = options.Limit nuchan, err := b.UserIndex.Search(nuchanSearch) if err != nil { - return nil, nil, model.NewAppError("Bleveengine.SearchUsersInChannel", "bleveengine.search_users_in_channel.nuchan.error", nil, err.Error(), http.StatusInternalServerError) + return nil, nil, model.NewAppError("Bleveengine.SearchUsersInChannel", "bleveengine.search_users_in_channel.nuchan.error", nil, "", http.StatusInternalServerError).Wrap(err) } uchanIds := []string{} @@ -540,7 +540,7 @@ func (b *BleveEngine) SearchUsersInTeam(teamId string, restrictedToChannels []st search.Size = options.Limit results, err := b.UserIndex.Search(search) if err != nil { - return nil, model.NewAppError("Bleveengine.SearchUsersInTeam", "bleveengine.search_users_in_team.error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("Bleveengine.SearchUsersInTeam", "bleveengine.search_users_in_team.error", nil, "", http.StatusInternalServerError).Wrap(err) } usersIds := []string{} @@ -556,7 +556,7 @@ func (b *BleveEngine) DeleteUser(user *model.User) *model.AppError { defer b.Mutex.RUnlock() if err := b.UserIndex.Delete(user.Id); err != nil { - return model.NewAppError("Bleveengine.DeleteUser", "bleveengine.delete_user.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.DeleteUser", "bleveengine.delete_user.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } @@ -567,7 +567,7 @@ func (b *BleveEngine) IndexFile(file *model.FileInfo, channelId string) *model.A blvFile := BLVFileFromFileInfo(file, channelId) if err := b.FileIndex.Index(blvFile.Id, blvFile); err != nil { - return model.NewAppError("Bleveengine.IndexFile", "bleveengine.index_file.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.IndexFile", "bleveengine.index_file.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } @@ -768,7 +768,7 @@ func (b *BleveEngine) SearchFiles(channels model.ChannelList, searchParams []*mo search.SortBy([]string{"-CreateAt"}) results, err := b.FileIndex.Search(search) if err != nil { - return nil, model.NewAppError("Bleveengine.SearchFiles", "bleveengine.search_files.error", nil, err.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("Bleveengine.SearchFiles", "bleveengine.search_files.error", nil, "", http.StatusInternalServerError).Wrap(err) } fileIds := []string{} @@ -785,7 +785,7 @@ func (b *BleveEngine) DeleteFile(fileID string) *model.AppError { defer b.Mutex.RUnlock() if err := b.FileIndex.Delete(fileID); err != nil { - return model.NewAppError("Bleveengine.DeleteFile", "bleveengine.delete_file.error", nil, err.Error(), http.StatusInternalServerError) + return model.NewAppError("Bleveengine.DeleteFile", "bleveengine.delete_file.error", nil, "", http.StatusInternalServerError).Wrap(err) } return nil } diff --git a/services/slackimport/slackimport.go b/services/slackimport/slackimport.go index 30e32afa37..03863b202a 100644 --- a/services/slackimport/slackimport.go +++ b/services/slackimport/slackimport.go @@ -122,7 +122,7 @@ func (si *SlackImporter) SlackImport(c request.CTX, fileData multipart.File, fil zipreader, err := zip.NewReader(fileData, fileSize) if err != nil || zipreader.File == nil { log.WriteString(i18n.T("api.slackimport.slack_import.zip.app_error")) - return model.NewAppError("SlackImport", "api.slackimport.slack_import.zip.app_error", nil, err.Error(), http.StatusBadRequest), log + return model.NewAppError("SlackImport", "api.slackimport.slack_import.zip.app_error", nil, "", http.StatusBadRequest).Wrap(err), log } var channels []slackChannel @@ -138,7 +138,7 @@ func (si *SlackImporter) SlackImport(c request.CTX, fileData multipart.File, fil fileReader, err := file.Open() if err != nil { log.WriteString(i18n.T("api.slackimport.slack_import.open.app_error", map[string]any{"Filename": file.Name})) - return model.NewAppError("SlackImport", "api.slackimport.slack_import.open.app_error", map[string]any{"Filename": file.Name}, err.Error(), http.StatusInternalServerError), log + return model.NewAppError("SlackImport", "api.slackimport.slack_import.open.app_error", map[string]any{"Filename": file.Name}, "", http.StatusInternalServerError).Wrap(err), log } reader := utils.NewLimitedReaderWithError(fileReader, slackImportMaxFileSize) if file.Name == "channels.json" { diff --git a/utils/license.go b/utils/license.go index c18b9fad7f..0c6b7dbe04 100644 --- a/utils/license.go +++ b/utils/license.go @@ -56,7 +56,7 @@ func (l *LicenseValidatorImpl) LicenseFromBytes(licenseBytes []byte) (*model.Lic var license model.License if jsonErr := json.Unmarshal([]byte(licenseStr), &license); jsonErr != nil { - return nil, model.NewAppError("LicenseFromBytes", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError) + return nil, model.NewAppError("LicenseFromBytes", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr) } return &license, nil diff --git a/web/context.go b/web/context.go index fb9dd48169..b46adb4a06 100644 --- a/web/context.go +++ b/web/context.go @@ -82,7 +82,7 @@ func (c *Context) MakeAuditRecord(event string, initialStatus string) *audit.Rec func (c *Context) LogAudit(extraInfo string) { audit := &model.Audit{UserId: c.AppContext.Session().UserId, IpAddress: c.AppContext.IPAddress(), Action: c.AppContext.Path(), ExtraInfo: extraInfo, SessionId: c.AppContext.Session().Id} if err := c.App.Srv().Store.Audit().Save(audit); err != nil { - appErr := model.NewAppError("LogAudit", "app.audit.save.saving.app_error", nil, err.Error(), http.StatusInternalServerError) + appErr := model.NewAppError("LogAudit", "app.audit.save.saving.app_error", nil, "", http.StatusInternalServerError).Wrap(err) c.LogErrorByCode(appErr) } } @@ -94,7 +94,7 @@ func (c *Context) LogAuditWithUserId(userId, extraInfo string) { audit := &model.Audit{UserId: userId, IpAddress: c.AppContext.IPAddress(), Action: c.AppContext.Path(), ExtraInfo: extraInfo, SessionId: c.AppContext.Session().Id} if err := c.App.Srv().Store.Audit().Save(audit); err != nil { - appErr := model.NewAppError("LogAuditWithUserId", "app.audit.save.saving.app_error", nil, err.Error(), http.StatusInternalServerError) + appErr := model.NewAppError("LogAuditWithUserId", "app.audit.save.saving.app_error", nil, "", http.StatusInternalServerError).Wrap(err) c.LogErrorByCode(appErr) } } @@ -164,7 +164,7 @@ func (c *Context) MfaRequired() { user, err := c.App.GetUser(c.AppContext.Session().UserId) if err != nil { - c.Err = model.NewAppError("MfaRequired", "api.context.get_user.app_error", nil, err.Error(), http.StatusUnauthorized) + c.Err = model.NewAppError("MfaRequired", "api.context.get_user.app_error", nil, "", http.StatusUnauthorized).Wrap(err) return } diff --git a/web/saml.go b/web/saml.go index 24ff06c530..592e638b7c 100644 --- a/web/saml.go +++ b/web/saml.go @@ -91,7 +91,7 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) { stateStr := "" b, err := b64.StdEncoding.DecodeString(relayState) if err != nil { - c.Err = model.NewAppError("completeSaml", "api.user.authorize_oauth_user.invalid_state.app_error", nil, err.Error(), http.StatusFound) + c.Err = model.NewAppError("completeSaml", "api.user.authorize_oauth_user.invalid_state.app_error", nil, "", http.StatusFound).Wrap(err) return } stateStr = string(b) @@ -165,7 +165,7 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAuditWithUserId(user.Id, "Revoked all sessions for user") c.App.Srv().Go(func() { if err := c.App.Srv().EmailService.SendSignInChangeEmail(user.Email, strings.Title(model.UserAuthServiceSaml)+" SSO", user.Locale, c.App.GetSiteURL()); err != nil { - c.LogErrorByCode(model.NewAppError("SendSignInChangeEmail", "api.user.send_sign_in_change_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError)) + c.LogErrorByCode(model.NewAppError("SendSignInChangeEmail", "api.user.send_sign_in_change_email_and_forget.error", nil, "", http.StatusInternalServerError).Wrap(err)) } }) } diff --git a/web/webhook.go b/web/webhook.go index a54e72e301..a705930b96 100644 --- a/web/webhook.go +++ b/web/webhook.go @@ -110,7 +110,7 @@ func commandWebhook(c *Context, w http.ResponseWriter, r *http.Request) { response, err := model.CommandResponseFromHTTPBody(r.Header.Get("Content-Type"), r.Body) if err != nil { - c.Err = model.NewAppError("commandWebhook", "web.command_webhook.parse.app_error", nil, err.Error(), http.StatusBadRequest) + c.Err = model.NewAppError("commandWebhook", "web.command_webhook.parse.app_error", nil, "", http.StatusBadRequest).Wrap(err) return }