diff --git a/server/api/post_action.go b/server/api/post_action.go index 841e029e..09e19905 100644 --- a/server/api/post_action.go +++ b/server/api/post_action.go @@ -50,7 +50,7 @@ func (api *api) postActionAccept(w http.ResponseWriter, req *http.Request) { } err := mscalendar.AcceptEvent(user, eventID) if err != nil { - api.Logger.Warnf(err.Error()) + api.Logger.Warnf("Failed to accept event. err=%v", err) utils.SlackAttachmentError(w, "Error: Failed to accept event: "+err.Error()) return } diff --git a/server/command/command.go b/server/command/command.go index 4c97a0e4..5109fd22 100644 --- a/server/command/command.go +++ b/server/command/command.go @@ -100,7 +100,7 @@ func (c *Command) isValid() (subcommand string, parameters []string, err error) split := strings.Fields(c.Args.Command) command := split[0] if command != "/"+config.CommandTrigger { - return "", nil, errors.Errorf("%q is not a supported command. Please contact your system administrator.", command) + return "", nil, fmt.Errorf("%q is not a supported command. Please contact your system administrator.", command) } parameters = []string{} diff --git a/server/command/create_event.go b/server/command/create_event.go index 405c1e48..ff52585f 100644 --- a/server/command/create_event.go +++ b/server/command/create_event.go @@ -6,10 +6,11 @@ import ( "strings" "time" - "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" - "github.com/mattermost/mattermost-plugin-mscalendar/server/utils" "github.com/pkg/errors" flag "github.com/spf13/pflag" + + "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" + "github.com/mattermost/mattermost-plugin-mscalendar/server/utils" ) func getCreateEventFlagSet() *flag.FlagSet { @@ -82,13 +83,13 @@ func parseCreateArgs(args []string, timeZone string) (*remote.Event, error) { }) for _, req := range requiredFlags { if !flags[req] { - return nil, errors.Errorf("Missing required flag: `--%s` ", req) + return nil, fmt.Errorf("Missing required flag: `--%s` ", req) } } help, err := createFlagSet.GetBool("help") if help == true { - return nil, errors.Errorf(getCreateEventFlagSet().FlagUsages()) + return nil, errors.New(getCreateEventFlagSet().FlagUsages()) } subject, err := createFlagSet.GetString("test-subject") @@ -97,7 +98,7 @@ func parseCreateArgs(args []string, timeZone string) (*remote.Event, error) { } // check that next arg is not a flag "--" if strings.HasPrefix(subject, "--") { - return nil, errors.Errorf("test-subject flag requires an argument") + return nil, errors.New("test-subject flag requires an argument") } event.Subject = subject @@ -107,7 +108,7 @@ func parseCreateArgs(args []string, timeZone string) (*remote.Event, error) { } // check that next arg is not a flag "--" if strings.HasPrefix(body, "--") { - return nil, errors.Errorf("body flag requires an argument") + return nil, errors.New("body flag requires an argument") } event.Body = &remote.ItemBody{ Content: body, @@ -118,7 +119,7 @@ func parseCreateArgs(args []string, timeZone string) (*remote.Event, error) { return nil, err } if strings.HasPrefix(startTime, "--") { - return nil, errors.Errorf("starttime flag requires an argument") + return nil, errors.New("starttime flag requires an argument") } event.Start = &remote.DateTime{ DateTime: startTime, @@ -130,7 +131,7 @@ func parseCreateArgs(args []string, timeZone string) (*remote.Event, error) { return nil, err } if strings.HasPrefix(endTime, "--") { - return nil, errors.Errorf("endtime flag requires an argument") + return nil, errors.New("endtime flag requires an argument") } event.End = &remote.DateTime{ DateTime: endTime, @@ -148,7 +149,7 @@ func parseCreateArgs(args []string, timeZone string) (*remote.Event, error) { return nil, err } if strings.HasPrefix(strconv.Itoa(int(reminder)), "--") { - return nil, errors.Errorf("reminder flag requires an argument") + return nil, errors.New("reminder flag requires an argument") } event.ReminderMinutesBeforeStart = reminder @@ -158,7 +159,7 @@ func parseCreateArgs(args []string, timeZone string) (*remote.Event, error) { } if len(location) != 0 { if len(location) != 6 { - return nil, errors.Errorf("test-location flag requires 6 parameters, including a comma for empty values") + return nil, errors.New("test-location flag requires 6 parameters, including a comma for empty values") } event.Location = &remote.Location{ LocationType: "default", diff --git a/server/jobs/daily_summary_job.go b/server/jobs/daily_summary_job.go index 5ca623c0..6e148950 100644 --- a/server/jobs/daily_summary_job.go +++ b/server/jobs/daily_summary_job.go @@ -30,7 +30,7 @@ func runDailySummaryJob(env mscalendar.Env) { err := mscalendar.New(env, "").ProcessAllDailySummary(time.Now()) if err != nil { - env.Logger.Errorf("Error during daily summary job: %v", err) + env.Logger.Errorf("Error during daily summary job. err=%v", err) } env.Logger.Debugf("Daily summary job finished") diff --git a/server/jobs/job_manager.go b/server/jobs/job_manager.go index acf11911..f6b6429c 100644 --- a/server/jobs/job_manager.go +++ b/server/jobs/job_manager.go @@ -5,13 +5,13 @@ package jobs import ( "context" + "fmt" "io" "sync" "time" "github.com/mattermost/mattermost-plugin-api/cluster" "github.com/mattermost/mattermost-plugin-mscalendar/server/mscalendar" - "github.com/pkg/errors" ) type JobManager struct { @@ -56,10 +56,8 @@ func NewJobManager(papi cluster.JobPluginAPI, env mscalendar.Env) *JobManager { } // AddJob accepts a RegisteredJob, stores it, and activates it if enabled. -func (jm *JobManager) AddJob(job RegisteredJob) error { +func (jm *JobManager) AddJob(job RegisteredJob) { jm.registeredJobs.Store(job.id, job) - - return nil } // OnConfigurationChange activates/deactivates jobs based on their current state, and the current plugin config. @@ -77,7 +75,7 @@ func (jm *JobManager) OnConfigurationChange(env mscalendar.Env) error { if enabled && !active { err := jm.activateJob(job) if err != nil { - jm.env.Logger.Errorf("Error activating %s job: %v", job.id, err) + jm.env.Logger.Warnf("Error activating %s job. err=%v", job.id, err) } } @@ -85,7 +83,7 @@ func (jm *JobManager) OnConfigurationChange(env mscalendar.Env) error { if !enabled && active { err := jm.deactivateJob(job) if err != nil { - jm.env.Logger.Errorf("Error deactivating %s job: %v", job.id, err) + jm.env.Logger.Warnf("Error deactivating %s job. err=%v", job.id, err) } } @@ -125,7 +123,7 @@ func (jm *JobManager) activateJob(job RegisteredJob) error { func (jm *JobManager) deactivateJob(job RegisteredJob) error { v, ok := jm.activeJobs.Load(job.id) if !ok { - return errors.Errorf("Attempted to deactivate a non-active job %s", job.id) + return fmt.Errorf("Attempted to deactivate a non-active job %s", job.id) } scheduledJob := v.(*activeJob) diff --git a/server/jobs/renew_job.go b/server/jobs/renew_job.go index db8aa802..f81c176e 100644 --- a/server/jobs/renew_job.go +++ b/server/jobs/renew_job.go @@ -23,7 +23,7 @@ func NewRenewJob() RegisteredJob { func runRenewJob(env mscalendar.Env) { uindex, err := env.Store.LoadUserIndex() if err != nil { - env.Logger.Errorf("Renew job failed to load user index: %s", err.Error()) + env.Logger.Errorf("Renew job failed to load user index. err=%v", err) return } env.Logger.Debugf("Renew job: %v users", len(uindex)) @@ -33,7 +33,7 @@ func runRenewJob(env mscalendar.Env) { env.Logger.Debugf("Renewing for user: %s", u.MattermostUserID) _, err = asUser.RenewMyEventSubscription() if err != nil { - env.Logger.Errorf("Error renewing subscription: %s", err.Error()) + env.Logger.Errorf("Error renewing subscription. err=%v", err) } time.Sleep(ditherRenew) diff --git a/server/jobs/status_sync_job.go b/server/jobs/status_sync_job.go index 62110bb7..3607d879 100644 --- a/server/jobs/status_sync_job.go +++ b/server/jobs/status_sync_job.go @@ -26,7 +26,7 @@ func runSyncJob(env mscalendar.Env) { _, err := mscalendar.New(env, "").SyncAll() if err != nil { - env.Logger.Errorf("Error during user status sync job: %v", err) + env.Logger.Errorf("Error during user status sync job. err=%v", err) } env.Logger.Debugf("User status sync job finished") diff --git a/server/mscalendar/availability.go b/server/mscalendar/availability.go index 748b3d4a..d3789fd0 100644 --- a/server/mscalendar/availability.go +++ b/server/mscalendar/availability.go @@ -113,7 +113,7 @@ func (m *mscalendar) deliverReminders(users []*store.User, calendarViews []*remo continue } if view.Error != nil { - m.Logger.Warnf("Error getting availability for %s: %s", user.Remote.Mail, view.Error.Message) + m.Logger.Warnf("Error getting availability for %s. err=%s", user.Remote.Mail, view.Error.Message) continue } @@ -156,7 +156,7 @@ func (m *mscalendar) setUserStatuses(users []*store.User, calendarViews []*remot continue } if view.Error != nil { - m.Logger.Warnf("Error getting availability for %s: %s", user.Remote.Mail, view.Error.Message) + m.Logger.Warnf("Error getting availability for %s. err=%s", user.Remote.Mail, view.Error.Message) continue } @@ -169,7 +169,7 @@ func (m *mscalendar) setUserStatuses(users []*store.User, calendarViews []*remot var err error res, err = m.setStatusFromCalendarView(user, status, view) if err != nil { - m.Logger.Warnf("Error setting user %s status. %s", user.Remote.Mail, err.Error()) + m.Logger.Warnf("Error setting user %s status. err=%v", user.Remote.Mail, err) } } if res != "" { @@ -321,19 +321,19 @@ func (m *mscalendar) notifyUpcomingEvents(mattermostUserID string, events []*rem if timezone == "" { timezone, err = m.GetTimezoneByID(mattermostUserID) if err != nil { - m.Logger.Warnf("notifyUpcomingEvents error getting timezone, err=%s", err.Error()) + m.Logger.Warnf("notifyUpcomingEvents error getting timezone. err=%v", err) return } } message, err := views.RenderUpcomingEvent(event, timezone) if err != nil { - m.Logger.Warnf("notifyUpcomingEvent error rendering schedule item, err=", err.Error()) + m.Logger.Warnf("notifyUpcomingEvent error rendering schedule item. err=%v", err) continue } _, err = m.Poster.DM(mattermostUserID, message) if err != nil { - m.Logger.Warnf("notifyUpcomingEvents error creating DM, err=", err.Error()) + m.Logger.Warnf("notifyUpcomingEvents error creating DM. err=%v", err) continue } } diff --git a/server/mscalendar/availability_test.go b/server/mscalendar/availability_test.go index da95e2fb..97aaee0c 100644 --- a/server/mscalendar/availability_test.go +++ b/server/mscalendar/availability_test.go @@ -132,7 +132,7 @@ func TestSyncStatusAll(t *testing.T) { } if tc.shouldLogError { - logger.EXPECT().Warnf("Error getting availability for %s: %s", "user_email@example.com", tc.apiError.Message).Times(1) + logger.EXPECT().Warnf("Error getting availability for %s. err=%s", "user_email@example.com", tc.apiError.Message).Times(1) } else { logger.EXPECT().Warnf(gomock.Any()).Times(0) } @@ -291,7 +291,7 @@ func TestReminders(t *testing.T) { } if tc.shouldLogError { - logger.EXPECT().Warnf("Error getting availability for %s: %s", "user_email@example.com", tc.apiError.Message).Times(1) + logger.EXPECT().Warnf("Error getting availability for %s. err=%s", "user_email@example.com", tc.apiError.Message).Times(1) } else { logger.EXPECT().Warnf(gomock.Any()).Times(0) } diff --git a/server/mscalendar/daily_summary.go b/server/mscalendar/daily_summary.go index b4b31b6c..55a2ad0b 100644 --- a/server/mscalendar/daily_summary.go +++ b/server/mscalendar/daily_summary.go @@ -4,6 +4,7 @@ package mscalendar import ( + "fmt" "time" "github.com/mattermost/mattermost-plugin-mscalendar/server/mscalendar/views" @@ -50,7 +51,7 @@ func (m *mscalendar) SetDailySummaryPostTime(user *User, timeStr string) (*store } if t.Minute()%int(DailySummaryJobInterval/time.Minute) != 0 { - return nil, errors.Errorf("Time must be a multiple of %d minutes.", DailySummaryJobInterval/time.Minute) + return nil, fmt.Errorf("Time must be a multiple of %d minutes.", DailySummaryJobInterval/time.Minute) } timezone, err := m.GetTimezone(user) @@ -119,7 +120,7 @@ func (m *mscalendar) ProcessAllDailySummary(now time.Time) error { for _, dsum := range dsumIndex { shouldPost, shouldPostErr := shouldPostDailySummary(dsum, now) if shouldPostErr != nil { - m.Logger.Errorf("Error posting daily summary for user %s: %v", dsum.MattermostUserID, shouldPostErr) + m.Logger.Warnf("Error posting daily summary for user %s. err=%v", dsum.MattermostUserID, shouldPostErr) continue } if !shouldPost { @@ -145,11 +146,11 @@ func (m *mscalendar) ProcessAllDailySummary(now time.Time) error { for _, res := range responses { dsum := byRemoteID[res.RemoteUserID] if res.Error != nil { - m.Logger.Errorf("Error rendering user %s calendar: %s %s", dsum.MattermostUserID, res.Error.Code, res.Error.Message) + m.Logger.Warnf("Error rendering user %s calendar. err=%s %s", dsum.MattermostUserID, res.Error.Code, res.Error.Message) } postStr, err := views.RenderCalendarView(res.Events, dsum.Timezone) if err != nil { - m.Logger.Errorf("Error rendering user %s calendar: %v", dsum.MattermostUserID, err) + m.Logger.Warnf("Error rendering user %s calendar. err=%v", dsum.MattermostUserID, err) } m.Poster.DM(dsum.MattermostUserID, postStr) diff --git a/server/mscalendar/notification.go b/server/mscalendar/notification.go index c22602f7..ea328f81 100644 --- a/server/mscalendar/notification.go +++ b/server/mscalendar/notification.go @@ -87,7 +87,7 @@ func (processor *notificationProcessor) Enqueue(notifications ...*remote.Notific select { case processor.queue <- n: default: - return errors.Errorf("webhook notification: queue full, dropped notification") + return fmt.Errorf("webhook notification: queue full, dropped notification") } } return nil diff --git a/server/mscalendar/oauth2.go b/server/mscalendar/oauth2.go index 508d1b55..a2df8627 100644 --- a/server/mscalendar/oauth2.go +++ b/server/mscalendar/oauth2.go @@ -36,7 +36,7 @@ func NewOAuth2App(env Env) oauth2connect.App { func (app *oauth2App) InitOAuth2(mattermostUserID string) (url string, err error) { user, err := app.Store.LoadUser(mattermostUserID) if err == nil { - return "", errors.Errorf("User is already connected to %s", user.Remote.Mail) + return "", fmt.Errorf("User is already connected to %s", user.Remote.Mail) } conf := app.Remote.NewOAuth2Config() @@ -83,11 +83,11 @@ func (app *oauth2App) CompleteOAuth2(authedUserID, code, state string) error { user, userErr := app.PluginAPI.GetMattermostUser(uid) if userErr == nil { app.Poster.DM(authedUserID, RemoteUserAlreadyConnected, config.ApplicationName, me.Mail, config.CommandTrigger, user.Username) - return errors.Errorf(RemoteUserAlreadyConnected, config.ApplicationName, me.Mail, config.CommandTrigger, user.Username) + return fmt.Errorf(RemoteUserAlreadyConnected, config.ApplicationName, me.Mail, config.CommandTrigger, user.Username) } else { // Couldn't fetch connected MM account. Reject connect attempt. app.Poster.DM(authedUserID, RemoteUserAlreadyConnectedNotFound, config.ApplicationName, me.Mail) - return errors.Errorf(RemoteUserAlreadyConnectedNotFound, config.ApplicationName, me.Mail) + return fmt.Errorf(RemoteUserAlreadyConnectedNotFound, config.ApplicationName, me.Mail) } } diff --git a/server/mscalendar/settings.go b/server/mscalendar/settings.go index 01df256b..428029ff 100644 --- a/server/mscalendar/settings.go +++ b/server/mscalendar/settings.go @@ -18,7 +18,7 @@ func (c *mscalendar) PrintSettings(userID string) { func (c *mscalendar) ClearSettingsPosts(userID string) { err := c.SettingsPanel.Clear(userID) if err != nil { - c.Logger.Warnf("error clearing settings posts, " + err.Error()) + c.Logger.Warnf("Error clearing settings posts. err=%v", err) } } diff --git a/server/mscalendar/settings_daily_summary.go b/server/mscalendar/settings_daily_summary.go index 645ec7c2..271a0bf1 100644 --- a/server/mscalendar/settings_daily_summary.go +++ b/server/mscalendar/settings_daily_summary.go @@ -134,7 +134,7 @@ func (s *dailySummarySetting) GetSlackAttachments(userID, settingHandler string, timezone, err := s.getTimezone(userID) if err != nil { - return nil, errors.New("could not load the timezone from Microsoft, err= " + err.Error()) + return nil, fmt.Errorf("could not load the timezone from Microsoft. err=%v", err) } fullTime = fullTime + " " + timezone diff --git a/server/mscalendar/user.go b/server/mscalendar/user.go index 5e08e086..1b868f26 100644 --- a/server/mscalendar/user.go +++ b/server/mscalendar/user.go @@ -138,7 +138,7 @@ func (m *mscalendar) DisconnectUser(mattermostUserID string) error { err = m.client.DeleteSubscription(eventSubscriptionID) if err != nil { - m.Logger.Errorf("failed to delete remote subscription %s: %v", eventSubscriptionID, err) + m.Logger.Warnf("failed to delete remote subscription %s. err=%v", eventSubscriptionID, err) } } diff --git a/server/mscalendar/welcomer.go b/server/mscalendar/welcomer.go index 5926d284..d4b5f6c7 100644 --- a/server/mscalendar/welcomer.go +++ b/server/mscalendar/welcomer.go @@ -74,7 +74,7 @@ func (bot *mscBot) Welcome(userID string) error { func (bot *mscBot) AfterSuccessfullyConnect(userID, userLogin string) error { postID, err := bot.Store.DeleteUserWelcomePost(userID) if err != nil { - bot.Errorf("error deleting user welcom post id, err=" + err.Error()) + bot.Errorf("error deleting user's welcome post id, err=%v", err) } if postID != "" { post := &model.Post{ @@ -137,7 +137,7 @@ func (bot *mscBot) cleanWelcomePost(mattermostUserID string) error { if postID != "" { err = bot.DeletePost(postID) if err != nil { - bot.Errorf(err.Error()) + bot.Errorf("Error deleting post. err=%v", err) } } return nil diff --git a/server/plugin/plugin.go b/server/plugin/plugin.go index 76f69a71..660f7742 100644 --- a/server/plugin/plugin.go +++ b/server/plugin/plugin.go @@ -79,7 +79,7 @@ func (p *Plugin) OnDeactivate() error { e := p.getEnv() if e.jobManager != nil { if err := e.jobManager.Close(); err != nil { - p.env.Logger.Errorf("OnDeactivate: Failed to close job manager: %v", err) + p.env.Logger.Warnf("OnDeactivate: Failed to close job manager. err=%v", err) return err } } @@ -164,23 +164,14 @@ func (p *Plugin) OnConfigurationChange() (err error) { if e.jobManager == nil { e.jobManager = jobs.NewJobManager(p.API, e.Env) - err := e.jobManager.AddJob(jobs.NewStatusSyncJob()) - if err != nil { - e.Logger.Errorf(err.Error()) - } - err = e.jobManager.AddJob(jobs.NewDailySummaryJob()) - if err != nil { - e.Logger.Errorf(err.Error()) - } - err = e.jobManager.AddJob(jobs.NewRenewJob()) - if err != nil { - e.Logger.Errorf(err.Error()) - } + e.jobManager.AddJob(jobs.NewStatusSyncJob()) + e.jobManager.AddJob(jobs.NewDailySummaryJob()) + e.jobManager.AddJob(jobs.NewRenewJob()) } err := e.jobManager.OnConfigurationChange(e.Env) if err != nil { - e.Logger.Errorf(err.Error()) + e.Logger.Errorf("Error updating job manager with config. err=%v", err) } }) diff --git a/server/remote/msgraph/create_calendar.go b/server/remote/msgraph/create_calendar.go index de9970ac..e7429295 100644 --- a/server/remote/msgraph/create_calendar.go +++ b/server/remote/msgraph/create_calendar.go @@ -6,6 +6,8 @@ package msgraph import ( "net/http" + "github.com/pkg/errors" + "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" "github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot" ) @@ -15,10 +17,10 @@ func (c *client) CreateCalendar(remoteUserID string, calIn *remote.Calendar) (*r var calOut = remote.Calendar{} err := c.rbuilder.Users().ID(remoteUserID).Calendars().Request().JSONRequest(c.ctx, http.MethodPost, "", &calIn, &calOut) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph CreateCalendar") } c.Logger.With(bot.LogContext{ "v": calOut, - }).Infof("msgraph: CreateCalendars created the following calendar.") + }).Infof("msgraph: CreateCalendar created the following calendar.") return &calOut, nil } diff --git a/server/remote/msgraph/create_event.go b/server/remote/msgraph/create_event.go index 5b5b234b..715a98e3 100644 --- a/server/remote/msgraph/create_event.go +++ b/server/remote/msgraph/create_event.go @@ -6,6 +6,8 @@ package msgraph import ( "net/http" + "github.com/pkg/errors" + "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" ) @@ -14,7 +16,7 @@ func (c *client) CreateEvent(remoteUserID string, in *remote.Event) (*remote.Eve var out = remote.Event{} err := c.rbuilder.Users().ID(remoteUserID).Events().Request().JSONRequest(c.ctx, http.MethodPost, "", &in, &out) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph CreateEvent") } return &out, nil } diff --git a/server/remote/msgraph/delete_calendar.go b/server/remote/msgraph/delete_calendar.go index 5d0a5e97..2d8ffc50 100644 --- a/server/remote/msgraph/delete_calendar.go +++ b/server/remote/msgraph/delete_calendar.go @@ -3,12 +3,16 @@ package msgraph -import "github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot" +import ( + "github.com/pkg/errors" + + "github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot" +) func (c *client) DeleteCalendar(remoteUserID string, calID string) error { err := c.rbuilder.Users().ID(remoteUserID).Calendars().ID(calID).Request().Delete(c.ctx) if err != nil { - return err + return errors.Wrap(err, "msgraph DeleteCalendar") } c.Logger.With(bot.LogContext{}).Infof("msgraph: DeleteCalendar deleted calendar `%v`.", calID) return nil diff --git a/server/remote/msgraph/event.go b/server/remote/msgraph/event.go index baed7e1f..beab2469 100644 --- a/server/remote/msgraph/event.go +++ b/server/remote/msgraph/event.go @@ -6,6 +6,7 @@ package msgraph import ( "net/http" + "github.com/pkg/errors" msgraph "github.com/yaegashi/msgraph.go/v1.0" "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" @@ -17,22 +18,34 @@ func (c *client) GetEvent(remoteUserID, eventID string) (*remote.Event, error) { err := c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).Request().JSONRequest( c.ctx, http.MethodGet, "", nil, &e) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph GetEvent") } return e, nil } func (c *client) AcceptEvent(remoteUserID, eventID string) error { dummy := &msgraph.EventAcceptRequestParameter{} - return c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).Accept(dummy).Request().Post(c.ctx) + err := c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).Accept(dummy).Request().Post(c.ctx) + if err != nil { + return errors.Wrap(err, "msgraph Accept Event") + } + return nil } func (c *client) DeclineEvent(remoteUserID, eventID string) error { dummy := &msgraph.EventDeclineRequestParameter{} - return c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).Decline(dummy).Request().Post(c.ctx) + err := c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).Decline(dummy).Request().Post(c.ctx) + if err != nil { + return errors.Wrap(err, "msgraph DeclineEvent") + } + return nil } func (c *client) TentativelyAcceptEvent(remoteUserID, eventID string) error { dummy := &msgraph.EventTentativelyAcceptRequestParameter{} - return c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).TentativelyAccept(dummy).Request().Post(c.ctx) + err := c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).TentativelyAccept(dummy).Request().Post(c.ctx) + if err != nil { + return errors.Wrap(err, "msgraph TentativelyAcceptEvent") + } + return nil } diff --git a/server/remote/msgraph/find_meeting_times.go b/server/remote/msgraph/find_meeting_times.go index 4311d265..30e1f21b 100644 --- a/server/remote/msgraph/find_meeting_times.go +++ b/server/remote/msgraph/find_meeting_times.go @@ -6,6 +6,8 @@ package msgraph import ( "net/http" + "github.com/pkg/errors" + "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" ) @@ -15,7 +17,7 @@ func (c *client) FindMeetingTimes(remoteUserID string, params *remote.FindMeetin req := c.rbuilder.Users().ID(remoteUserID).FindMeetingTimes(nil).Request() err := req.JSONRequest(c.ctx, http.MethodPost, "", ¶ms, &meetingsOut) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph FindMeetingTimes") } return meetingsOut, nil } diff --git a/server/remote/msgraph/get_calendars.go b/server/remote/msgraph/get_calendars.go index 8f187977..c85ea3e8 100644 --- a/server/remote/msgraph/get_calendars.go +++ b/server/remote/msgraph/get_calendars.go @@ -6,6 +6,8 @@ package msgraph import ( "net/http" + "github.com/pkg/errors" + "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" "github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot" ) @@ -18,7 +20,7 @@ func (c *client) GetCalendars(remoteUserID string) ([]*remote.Calendar, error) { req.Expand("children") err := req.JSONRequest(c.ctx, http.MethodGet, "", nil, &v) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph GetCalendars") } c.Logger.With(bot.LogContext{ "UserID": remoteUserID, diff --git a/server/remote/msgraph/get_default_calendar_view.go b/server/remote/msgraph/get_default_calendar_view.go index 0f8bc06c..74a7e1e2 100644 --- a/server/remote/msgraph/get_default_calendar_view.go +++ b/server/remote/msgraph/get_default_calendar_view.go @@ -8,6 +8,8 @@ import ( "net/url" "time" + "github.com/pkg/errors" + "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" ) @@ -34,7 +36,7 @@ func (c *client) GetDefaultCalendarView(remoteUserID string, start, end time.Tim err := c.rbuilder.Users().ID(remoteUserID).CalendarView().Request().JSONRequest( c.ctx, http.MethodGet, paramStr, nil, res) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph GetDefaultCalendarView") } return res.Value, nil @@ -59,7 +61,7 @@ func (c *client) DoBatchViewCalendarRequests(allParams []*remote.ViewCalendarPar batchRes := &calendarViewBatchResponse{} err := c.batchRequest(req, batchRes) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph ViewCalendar batch request") } batchResponses = append(batchResponses, batchRes) diff --git a/server/remote/msgraph/get_mailbox_settings.go b/server/remote/msgraph/get_mailbox_settings.go index 94661b0a..e1231a7e 100644 --- a/server/remote/msgraph/get_mailbox_settings.go +++ b/server/remote/msgraph/get_mailbox_settings.go @@ -6,6 +6,8 @@ package msgraph import ( "net/http" + "github.com/pkg/errors" + "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" ) @@ -14,5 +16,8 @@ func (c *client) GetMailboxSettings(remoteUserID string) (*remote.MailboxSetting out := &remote.MailboxSettings{} _, err := c.CallJSON(http.MethodGet, u, nil, out) - return out, err + if err != nil { + return nil, errors.Wrap(err, "msgraph GetMailboxSettings") + } + return out, nil } diff --git a/server/remote/msgraph/get_me.go b/server/remote/msgraph/get_me.go index 2d6632c9..02503b10 100644 --- a/server/remote/msgraph/get_me.go +++ b/server/remote/msgraph/get_me.go @@ -4,7 +4,7 @@ package msgraph import ( - "errors" + "github.com/pkg/errors" "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" ) @@ -12,7 +12,7 @@ import ( func (c *client) GetMe() (*remote.User, error) { graphUser, err := c.rbuilder.Me().Request().Get(c.ctx) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph GetMe") } if graphUser.ID == nil { diff --git a/server/remote/msgraph/get_notification_data.go b/server/remote/msgraph/get_notification_data.go index d3013d58..8dabcdba 100644 --- a/server/remote/msgraph/get_notification_data.go +++ b/server/remote/msgraph/get_notification_data.go @@ -4,9 +4,10 @@ package msgraph import ( - "errors" "net/http" + "github.com/pkg/errors" + "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" "github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot" ) @@ -23,7 +24,7 @@ func (c *client) GetNotificationData(orig *remote.Notification) (*remote.Notific "Resource": wh.Resource, "subscriptionID": wh.SubscriptionID, }).Infof("msgraph: failed to fetch notification data resource: `%v`.", err) - return nil, err + return nil, errors.Wrap(err, "msgraph GetNotificationData") } n.Event = &event n.ChangeType = wh.ChangeType diff --git a/server/remote/msgraph/get_schedule_batched.go b/server/remote/msgraph/get_schedule_batched.go index f2caec5e..038e000f 100644 --- a/server/remote/msgraph/get_schedule_batched.go +++ b/server/remote/msgraph/get_schedule_batched.go @@ -3,6 +3,8 @@ package msgraph import ( "net/http" + "github.com/pkg/errors" + "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" ) @@ -60,7 +62,7 @@ func (c *client) GetSchedule(requests []*remote.ScheduleUserInfo, startTime, end res := &getScheduleBatchResponse{} err := c.batchRequest(req, res) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph batch GetSchedule") } batchResponses = append(batchResponses, res) @@ -72,7 +74,7 @@ func (c *client) GetSchedule(requests []*remote.ScheduleUserInfo, startTime, end if r.Body.Error == nil { result = append(result, r.Body.Value...) } else { - c.Errorf("Failed to process schedule. %s", r.Body.Error.Message) + c.Warnf("Failed to process schedule. err=%s", r.Body.Error.Message) } } } diff --git a/server/remote/msgraph/get_super_user_token.go b/server/remote/msgraph/get_super_user_token.go index 8a8158c4..d9c7a693 100644 --- a/server/remote/msgraph/get_super_user_token.go +++ b/server/remote/msgraph/get_super_user_token.go @@ -6,6 +6,8 @@ package msgraph import ( "net/http" "net/url" + + "github.com/pkg/errors" ) type AuthResponse struct { @@ -33,7 +35,7 @@ func (c *client) GetSuperuserToken() (string, error) { _, err := c.CallFormPost(http.MethodPost, u, data, &res) if err != nil { - return "", err + return "", errors.Wrap(err, "msgraph GetSuperuserToken") } return res.AccessToken, nil diff --git a/server/remote/msgraph/subscription.go b/server/remote/msgraph/subscription.go index 8ce81b4c..85e5848b 100644 --- a/server/remote/msgraph/subscription.go +++ b/server/remote/msgraph/subscription.go @@ -9,6 +9,8 @@ import ( "net/http" "time" + "github.com/pkg/errors" + "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" "github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot" ) @@ -31,7 +33,7 @@ func (c *client) CreateMySubscription(notificationURL string) (*remote.Subscript } err := c.rbuilder.Subscriptions().Request().JSONRequest(c.ctx, http.MethodPost, "", sub, sub) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph CreateMySubscription") } c.Logger.With(bot.LogContext{ @@ -47,7 +49,7 @@ func (c *client) CreateMySubscription(notificationURL string) (*remote.Subscript func (c *client) DeleteSubscription(subscriptionID string) error { err := c.rbuilder.Subscriptions().ID(subscriptionID).Request().Delete(c.ctx) if err != nil { - return err + return errors.Wrap(err, "msgraph DeleteSubscription") } c.Logger.With(bot.LogContext{ @@ -67,7 +69,7 @@ func (c *client) RenewSubscription(subscriptionID string) (*remote.Subscription, sub := remote.Subscription{} err := c.rbuilder.Subscriptions().ID(subscriptionID).Request().JSONRequest(c.ctx, http.MethodPatch, "", v, &sub) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph RenewSubscription") } c.Logger.With(bot.LogContext{ @@ -84,7 +86,7 @@ func (c *client) ListSubscriptions() ([]*remote.Subscription, error) { } err := c.rbuilder.Subscriptions().Request().JSONRequest(c.ctx, http.MethodGet, "", nil, &v) if err != nil { - return nil, err + return nil, errors.Wrap(err, "msgraph ListSubscriptions") } return v.Value, nil } diff --git a/server/store/subscription_store.go b/server/store/subscription_store.go index 930f61f3..de35a1be 100644 --- a/server/store/subscription_store.go +++ b/server/store/subscription_store.go @@ -4,7 +4,7 @@ package store import ( - "github.com/pkg/errors" + "fmt" "github.com/mattermost/mattermost-plugin-mscalendar/server/remote" "github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot" @@ -34,7 +34,7 @@ func (s *pluginStore) LoadSubscription(subscriptionID string) (*Subscription, er func (s *pluginStore) StoreUserSubscription(user *User, subscription *Subscription) error { if user.Remote.ID != subscription.Remote.CreatorID { - return errors.Errorf("User %q does not match the subscription creator %q", + return fmt.Errorf("User %q does not match the subscription creator %q", user.Remote.ID, subscription.Remote.CreatorID) } err := kvstore.StoreJSON(s.subscriptionKV, subscription.Remote.ID, subscription) diff --git a/server/utils/httputils/utils.go b/server/utils/httputils/utils.go index 4ec967bb..256c2359 100644 --- a/server/utils/httputils/utils.go +++ b/server/utils/httputils/utils.go @@ -5,12 +5,11 @@ package httputils import ( "encoding/json" + "fmt" "net/http" "net/url" "path" "strings" - - "github.com/pkg/errors" ) func NormalizeRemoteBaseURL(mattermostSiteURL, remoteURL string) (string, error) { @@ -30,7 +29,7 @@ func NormalizeRemoteBaseURL(mattermostSiteURL, remoteURL string) (string, error) } } if u.Host == "" { - return "", errors.Errorf("Invalid URL, no hostname: %q", remoteURL) + return "", fmt.Errorf("Invalid URL, no hostname: %q", remoteURL) } if u.Scheme == "" { u.Scheme = "https" @@ -38,7 +37,7 @@ func NormalizeRemoteBaseURL(mattermostSiteURL, remoteURL string) (string, error) remoteURL = strings.TrimSuffix(u.String(), "/") if remoteURL == strings.TrimSuffix(mattermostSiteURL, "/") { - return "", errors.Errorf("%s is the Mattermost site URL. Please use the remote application's URL.", remoteURL) + return "", fmt.Errorf("%s is the Mattermost site URL. Please use the remote application's URL.", remoteURL) } return remoteURL, nil diff --git a/server/utils/settingspanel/settings.go b/server/utils/settingspanel/settings.go index d6c63de0..fc2a546d 100644 --- a/server/utils/settingspanel/settings.go +++ b/server/utils/settingspanel/settings.go @@ -92,7 +92,7 @@ func (p *panel) URL() string { func (p *panel) Print(userID string) { err := p.cleanPreviousSettingsPosts(userID) if err != nil { - p.logger.Errorf("could not clean previous setting post, " + err.Error()) + p.logger.Warnf("could not clean previous setting post. err=%v", err) } sas := []*model.SlackAttachment{} @@ -100,20 +100,20 @@ func (p *panel) Print(userID string) { s := p.settings[key] sa, loopErr := s.GetSlackAttachments(userID, p.pluginURL+p.settingHandler, p.isSettingDisabled(userID, s)) if loopErr != nil { - p.logger.Errorf("error creating the slack attachment, err=" + loopErr.Error()) + p.logger.Warnf("error creating the slack attachment. err=%v", loopErr) continue } sas = append(sas, sa) } postID, err := p.poster.DMWithAttachments(userID, sas...) if err != nil { - p.logger.Errorf("error creating the message, err=", err.Error()) + p.logger.Warnf("error creating the message. err=%v", err) return } err = p.store.SetPanelPostID(userID, postID) if err != nil { - p.logger.Errorf("could not set the post IDs, err=", err.Error()) + p.logger.Warnf("could not set the post IDs. err=%v", err) } } @@ -125,7 +125,7 @@ func (p *panel) ToPost(userID string) (*model.Post, error) { s := p.settings[key] sa, err := s.GetSlackAttachments(userID, p.pluginURL+p.settingHandler, p.isSettingDisabled(userID, s)) if err != nil { - p.logger.Errorf("error creating the slack attachment for setting %s, err=%s", s.GetID(), err.Error()) + p.logger.Warnf("error creating the slack attachment for setting %s. err=%v", s.GetID(), err) continue } sas = append(sas, sa) @@ -147,7 +147,7 @@ func (p *panel) cleanPreviousSettingsPosts(userID string) error { err = p.poster.DeletePost(postID) if err != nil { - p.logger.Errorf("could not delete setting post, %s", err) + p.logger.Warnf("could not delete setting post. err=%v", err) } err = p.store.DeletePanelPostID(userID) @@ -169,13 +169,13 @@ func (p *panel) isSettingDisabled(userID string, s Setting) bool { } dependency, ok := p.settings[dependencyID] if !ok { - p.logger.Errorf("settings dependency %s not found", dependencyID) + p.logger.Warnf("settings dependency %s not found", dependencyID) return false } value, err := dependency.Get(userID) if err != nil { - p.logger.Errorf("cannot get dependency %s value", dependencyID) + p.logger.Warnf("cannot get dependency %s value. err=%v", dependencyID, err) return false } return s.IsDisabled(value)