Skip to content

Commit

Permalink
Throw error if task list is empty or task not found (#2543)
Browse files Browse the repository at this point in the history
* Add more logging

* Revert import order

* Add TODO
  • Loading branch information
shobhitagarwal1612 authored Jul 16, 2024
1 parent e7c8cad commit 52c6d54
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,20 @@ internal constructor(
* reversed is set, will generate the previous tasks from there.
*/
private fun getTaskSequence(startId: String? = null, reversed: Boolean = false): Sequence<Task> {
val startIndex = tasks.indexOf(tasks.first { it.id == (startId ?: tasks[0].id) })
if (tasks.isEmpty()) {
error("Can't generate sequence for empty task list")
}

val task = tasks.filter { it.id == (startId ?: tasks[0].id) }

// TODO(#2539): Cleanup once https://github.com/google/ground-android/issues/2539 is resolved.
if (task.isEmpty()) {
error(
"Unable to find a task with id startId=$startId, firstTaskId=${tasks[0].id}, allTasks=${tasks.map { it.id }}"
)
}

val startIndex = tasks.indexOf(task.first())
return if (reversed) {
tasks.subList(0, startIndex + 1).reversed()
} else {
Expand Down

0 comments on commit 52c6d54

Please sign in to comment.