Skip to content

Commit

Permalink
Added GetByID which returns an error
Browse files Browse the repository at this point in the history
  • Loading branch information
botto committed Feb 18, 2021
1 parent fda0b6e commit 675b77b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions taskset.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,19 @@ func (ts *TaskSet) FilterOrganised() {
}

func (ts *TaskSet) MustGetByID(id int) Task {
task, err := ts.GetByID(id)
if err != nil {
ExitFail(err.Error())
}
return *task
}

func (ts *TaskSet) GetByID(id int) (*Task, error) {
if ts.tasksByID[id] == nil {
ExitFail("No open task with ID %v exists.", id)
return nil, fmt.Errorf("no open task with ID %v exists.", id)
}

return *ts.tasksByID[id]
return ts.tasksByID[id], nil
}

func (ts *TaskSet) Tasks() []Task {
Expand Down

0 comments on commit 675b77b

Please sign in to comment.