Add checking and logging when trying to put a task into a nonexisting bucket

This commit is contained in:
kolaente 2020-05-07 10:20:10 +02:00
parent a30a358b73
commit 563fe16bd4
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 6 additions and 0 deletions

View File

@ -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)
}