From 563fe16bd466a142e1fe93fcc41892c024ee2a69 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 7 May 2020 10:20:10 +0200 Subject: [PATCH] Add checking and logging when trying to put a task into a nonexisting bucket --- pkg/models/kanban.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/models/kanban.go b/pkg/models/kanban.go index d93bef6b28..ebe3ce5861 100644 --- a/pkg/models/kanban.go +++ b/pkg/models/kanban.go @@ -17,6 +17,7 @@ package models import ( + "code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/timeutil" "code.vikunja.io/api/pkg/user" "code.vikunja.io/web" @@ -132,6 +133,11 @@ func (b *Bucket) ReadAll(auth web.Auth, search string, page int, perPage int) (r // All tasks which are not associated to any bucket will have bucket id 0 which is the nil value for int64 // Since we created a bucked with that id at the beginning, all tasks should be in there. for _, task := range tasks { + // Check if the bucket exists in the map to prevent nil pointer panics + if _, exists := bucketMap[task.BucketID]; !exists { + log.Debugf("Tried to put task %d into bucket %d which does not exist in list %d", task.ID, task.BucketID, b.ListID) + continue + } bucketMap[task.BucketID].Tasks = append(bucketMap[task.BucketID].Tasks, task) }