Skip to content

Commit

Permalink
Remove duplication log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
goyalmunish committed Jan 9, 2023
1 parent d172eea commit ee22a4b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 3 additions & 1 deletion cmd/reminder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func Run() error {
func RepeatInteractiveSession(reminderData *model.ReminderData) error {
var err error
// print data stats
fmt.Println(reminderData.Stats())
stats, err := reminderData.Stats()
fmt.Println(stats)
utils.LogError(err)
// try automatic backup
_, err = reminderData.AutoBackup(24 * 60 * 60)
utils.LogError(err)
Expand Down
17 changes: 7 additions & 10 deletions internal/model/reminder_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func (rd *ReminderData) SyncCalendar(calOptions *calendar.Options) error {
logger.Info("Retrieve the Cloud Calendar Service.")
srv, err := calendar.GetCalendarService(calOptions)
if err != nil {
logger.Error(fmt.Sprintf("Unable to retrieve Calendar client: %v", err))
return err
return fmt.Errorf("Unable to retrieve Calendar client: %w", err)
}

logger.Info("Fetch the list of all upcoming Calendar Events with each type of recurring event as single unit.")
Expand All @@ -63,8 +62,7 @@ func (rd *ReminderData) SyncCalendar(calOptions *calendar.Options) error {
MaxResults(250). // 250 is default and is maximum value; if there are more than 250 events, then we'll have to paginate
Do()
if err != nil {
logger.Error(fmt.Sprintf("Unable to retrieve the events: %v", err))
return err
return fmt.Errorf("Unable to retrieve the events: %w", err)
}

// Get Cloud Calendar details
Expand Down Expand Up @@ -104,8 +102,7 @@ func (rd *ReminderData) SyncCalendar(calOptions *calendar.Options) error {
Q(calendar.TitlePrefix).
Do()
if err != nil {
logger.Error(fmt.Sprintf("Unable to retrieve the events: %v", err))
return err
return fmt.Errorf("Unable to retrieve the events: %v", err)
}
fmt.Printf("Listing matching events (%v) and deleting the ones registered by reminder app:\n", len(reminderEvents.Items))
if len(reminderEvents.Items) == 0 {
Expand All @@ -125,8 +122,7 @@ func (rd *ReminderData) SyncCalendar(calOptions *calendar.Options) error {
continue
}
if err := srv.Events.Delete("primary", item.Id).Do(); err != nil {
logger.Error(fmt.Sprintf("Couldn't delete the Calendar event %q | %q | %v", item.Id, item.Summary, err))
return err
return fmt.Errorf("Couldn't delete the Calendar event %q | %q | %v", item.Id, item.Summary, err)
} else {
deletionCount += 1
fmt.Printf(" - Deleted the Calendar event %q | %q\n", item.Id, calendar.EventString(item))
Expand Down Expand Up @@ -156,7 +152,8 @@ func (rd *ReminderData) SyncCalendar(calOptions *calendar.Options) error {
}
_, err = srv.Events.Insert("primary", event).Do()
if err != nil {
logger.Error(err)
// just ignore, but log the error
utils.LogError(err)
}
logger.Info(fmt.Sprintf("Synced the event %q.\n", calendar.EventString(event)))
}
Expand Down Expand Up @@ -877,7 +874,7 @@ func (rd *ReminderData) PrintNotesAndAskOptions(notes Notes, display_mode string
fmt.Printf("Note: Using passed notes; the list will not be refreshed immediately!\n")
fmt.Printf("Note: You must not run multiple instances of the app on same data file!\n")
default:
logger.Error("Error: Unreachable code")
return errors.New("Error: Unreachable code")
}

// sort notes
Expand Down
2 changes: 1 addition & 1 deletion pkg/calendar/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func EventsDetails(events *gc.Events) (string, error) {
value, err := utils.StrToTime(events.Updated, events.TimeZone)
if err != nil {
logger.Error(err)
return "unparsable"
return ""
}
return value.String()
}
Expand Down

0 comments on commit ee22a4b

Please sign in to comment.