From 38b5c7fb6cc639240eda1575ebab1128030bd2e5 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 12 Oct 2020 19:33:17 +0200 Subject: [PATCH] Add checks if tasks exist in maps before trying to access them Signed-off-by: kolaente --- pkg/modules/migration/todoist/todoist.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/modules/migration/todoist/todoist.go b/pkg/modules/migration/todoist/todoist.go index 831eef1069..5a6f373470 100644 --- a/pkg/modules/migration/todoist/todoist.go +++ b/pkg/modules/migration/todoist/todoist.go @@ -309,6 +309,11 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa continue } + if _, exists := tasks[i.ParentID]; !exists { + log.Debugf("[Todoist Migration] Could not find task %d in tasks map while trying to get resolve subtasks for task %d", i.ParentID, i.ID) + continue + } + // Prevent all those nil errors if tasks[i.ParentID].RelatedTasks == nil { tasks[i.ParentID].RelatedTasks = make(models.RelatedTaskMap) @@ -332,6 +337,11 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa // Task Notes -> Task Descriptions // FIXME: Should be comments for _, n := range sync.Notes { + if _, exists := tasks[n.ItemID]; !exists { + log.Debugf("[Todoist Migration] Could not find task %d for note %d", n.ItemID, n.ID) + continue + } + if tasks[n.ItemID].Description != "" { tasks[n.ItemID].Description += "\n" } @@ -391,6 +401,10 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa continue } + if _, exists := tasks[r.ItemID]; !exists { + log.Debugf("Could not find task %d for reminder %d while trying to resolve reminders", r.ItemID, r.ID) + } + var err error var date time.Time date, err = time.Parse("2006-01-02T15:04:05Z", r.Due.Date)