dominikbraun / timetrace

A simple CLI for tracking your working time.
Apache License 2.0
685 stars 76 forks source link

`timetrace edit record` panics when there is no end time of the latest record #68

Closed dominikbraun closed 3 years ago

dominikbraun commented 3 years ago

Currently, running go run . edit record will panic in case the latest record has not been stopped yet - because in that case, the record's End field is nil. Editing a record using the --plus and --minus options should not be allowed if the latest record has no end yet.

adzo261 commented 3 years ago

Hi, I would like to do this one.

adzo261 commented 3 years ago
  1. I think handling the error before we access the End property of the Record struct will do.

    Potentially, adding this if block in the corresponding if-else blocks.:

    if record.End == nil {
        return errors.New("record is still in progress")
    }
  2. Also, do you think, we should extract the contents of the if-else blocks into a local function? Since both are doing the same things essentially. https://github.com/dominikbraun/timetrace/blob/9558282d72fdea96b456cc6a04c5667f96a18de5/core/record.go#L125-L142

dominikbraun commented 3 years ago
  1. Yes, that if block should be sufficient.
  2. I also thought about that. Feel tree to create a new function for that piece of logic. 😄