dominikbraun / timetrace

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

Error: Failed to start tracking #102

Closed udayravuri closed 3 years ago

udayravuri commented 3 years ago

Hi, After creating a project as per README usage instructions, whenever I try to start tracking I get this error on Mac: $ timetrace start coding ❗ Failed to start tracking: start tracking first

Please advise. Thank you!!

dominikbraun commented 3 years ago

Thanks for your bug report. Which timetrace version do you have installed? In case you're using Homebrew, use brew upgrade timetrace to make sure you have the latest version.


@joshuaherrera: This probably comes from Start calling LoadLatestRecord, which returns an ErrTrackingNotStarted:

https://github.com/dominikbraun/timetrace/blob/a17401f599296ada2e5a4f03dfd383a66155f590/core/record.go#L161-L179

Do you have an idea why this could happen? But let's see if @udayravuri has the latest version installed.

udayravuri commented 3 years ago

I barely installed, so hoping it installed the latest version. But let me try upgrading as you suggested.

udayravuri commented 3 years ago

Still the same issue: Warning: dominikbraun/timetrace/timetrace 0.7.1 already installed ELSM:~ ut$ timetrace start coding ❗ Failed to start tracking: start tracking first ELSM:~ ut$

dominikbraun commented 3 years ago

Alright, I could reproduce the issue. I'm going to come up with a patch release shortly.

udayravuri commented 3 years ago

Thank you very much @dominikbraun . Looks like from the code pasted above by you and @joshuaherrera , it's looking for Records. But it doesn't look like it has any in store after creating a fresh project, as seen below at least: ELSML03UR088T:~ ur088t$ timetrace list projects +-----+------------------+-----------+ | # | KEY | MODULES | +-----+------------------+-----------+ | 1 | ovfeatart2-24587 | - | +-----+------------------+-----------+ ELSML03UR088T:~ ur088t$ timetrace start ovfeatart2-24587 ❗ Failed to start tracking: start tracking first ELSML03UR088T:~ ur088t$ timetrace get project ovfeatart2-24587 +------------------+ | KEY | +------------------+ | ovfeatart2-24587 | +------------------+ ELSML03UR088T:~ ur088t$ timetrace start ovfeatart2-24587 ❗ Failed to start tracking: start tracking first ELSML03UR088T:~ ur088t$ timetrace list records today +-----+-------+-----------+---------+-------+------------+ | # | KEY | PROJECT | START | END | BILLABLE | +-----+-------+-----------+---------+-------+------------+ +-----+-------+-----------+---------+-------+------------+ ELSML03UR088T:~ ur088t$

dominikbraun commented 3 years ago

But it doesn't look like it has any in store after creating a fresh project, as seen below at least

Exactly. t.latestNonEmptyDir returns ErrAllDirectoriesEmpty since there are no records yet, which results in an ErrTrackingNotStarted.

joshuaherrera commented 3 years ago

But it doesn't look like it has any in store after creating a fresh project, as seen below at least

Exactly. t.latestNonEmptyDir returns ErrAllDirectoriesEmpty since there are no records yet, which results in an ErrTrackingNotStarted.

Yea I just looked into this and noticed the same thing. I don't think we'd need to account for this error when a user starts logging time, maybe we can just ensure the error returned is not ErrTrackingNotStarted ? It seems like we just load a record to ensure that the latest timelog has ended.

dominikbraun commented 3 years ago

@joshuaherrera Could you maybe review #103? This solves the problem for me, but I'm not sure whether it will have unwanted side effects.

joshuaherrera commented 3 years ago

@joshuaherrera Could you maybe review #103? This solves the problem for me, but I'm not sure whether it will have unwanted side effects.

Yes I will review.

KonstantinGasser commented 3 years ago

I also found a solution checking for the error in the timetrace.Start() func

func (t *Timetrace) Start(projectKey string, isBillable bool) error {
    latestRecord, err := t.LoadLatestRecord()
    if err != nil && !errors.Is(err, ErrTrackingNotStarted) { // checking if err is ErrTrackingNotStarted
        return err
    }

the variable latestRecord is only required for checking if a tracking is currently ongoing. #103 changes the logic the function name would suggest with LoadLatestRecord where if all dirs are empty the error seems to be appropriate.

dominikbraun commented 3 years ago

I also found a solution checking for the error in the timetrace.Start() func

func (t *Timetrace) Start(projectKey string, isBillable bool) error {
  latestRecord, err := t.LoadLatestRecord()
  if err != nil && !errors.Is(err, ErrTrackingNotStarted) { // checking if err is ErrTrackingNotStarted
      return err
  }

the variable latestRecord is only required for checking if a tracking is currently ongoing. #103 changes the logic the function name would suggest with LoadLatestRecord where if all dirs are empty the error seems to be appropriate.

Good point, I even prefer this solution as it avoids unknown side effects. I updated #103 accordingly.

dominikbraun commented 3 years ago

@udayravuri @joshuaherrera @KonstantinGasser Thanks everybody, the fix is contained in release 0.7.2.

@udayravuri You can now run brew upgrade timetrace again - maybe you could verify that everything works for you now.

udayravuri commented 3 years ago

I'm outside, will take about 3 hrs. Will post update as soon as I get home. Thank you!!

On Fri, Jun 4, 2021, 12:07 PM Dominik Braun @.***> wrote:

@udayravuri https://github.com/udayravuri @joshuaherrera https://github.com/joshuaherrera @KonstantinGasser https://github.com/KonstantinGasser Thanks everybody, the fix is contained in release 0.7.2 https://github.com/dominikbraun/timetrace/releases/tag/v0.7.2.

@udayravuri https://github.com/udayravuri You can now run brew upgrade timetrace again - maybe you could verify that everything works for you now.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dominikbraun/timetrace/issues/102#issuecomment-854943253, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACVICONJDDZHPQBZJ7TRIT3TREP7DANCNFSM46DH432Q .

udayravuri commented 3 years ago

@dominikbraun, I'm unable to install v0.7.2 using brew upgrade, please see below: ELSML03UR088T:~ ur088t$ brew upgrade timetrace Error: homebrew-core is a shallow clone. homebrew-cask is a shallow clone. To brew update, first run: git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow These commands may take a few minutes to run due to the large size of the repositories. This restriction has been made on GitHub's request because updating shallow clones is an extremely expensive operation due to the tree layout and traffic of Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you automatically to avoid repeatedly performing an expensive unshallow operation in CI systems (which should instead be fixed to not use shallow clones). Sorry for the inconvenience! Warning: dominikbraun/timetrace/timetrace 0.7.1 already installed ELSML03UR088T:~ ur088t$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow remote: Enumerating objects: 538058, done. remote: Counting objects: 100% (538020/538020), done. remote: Compressing objects: 100% (193653/193653), done. remote: Total 529414 (delta 338540), reused 523776 (delta 332914), pack-reused 0 Receiving objects: 100% (529414/529414), 201.98 MiB | 1.45 MiB/s, done. Resolving deltas: 100% (338540/338540), completed with 3969 local objects. From https://github.com/Homebrew/homebrew-core 94260977d2..c6a010d7be master -> origin/master ELSML03UR088T:~ ur088t$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow remote: Enumerating objects: 332303, done. remote: Counting objects: 100% (330282/330282), done. remote: Compressing objects: 100% (96683/96683), done. remote: Total 322241 (delta 229796), reused 317466 (delta 225021), pack-reused 0 Receiving objects: 100% (322241/322241), 120.68 MiB | 1.64 MiB/s, done. Resolving deltas: 100% (229796/229796), completed with 3180 local objects. From https://github.com/Homebrew/homebrew-cask a0b1f7a29e..30b263d39e master -> origin/master ELSML03UR088T:~ ur088t$ brew upgrade timetrace Warning: dominikbraun/timetrace/timetrace 0.7.1 already installed ELSML03UR088T:~ ur088t$

dominikbraun commented 3 years ago

@dominikbraun, I'm unable to install v0.7.2 using brew upgrade, please see below: ELSML03UR088T:~ ur088t$ brew upgrade timetrace Error: homebrew-core is a shallow clone. homebrew-cask is a shallow clone. To brew update, first run: git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow These commands may take a few minutes to run due to the large size of the repositories. This restriction has been made on GitHub's request because updating shallow clones is an extremely expensive operation due to the tree layout and traffic of Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you automatically to avoid repeatedly performing an expensive unshallow operation in CI systems (which should instead be fixed to not use shallow clones). Sorry for the inconvenience! Warning: dominikbraun/timetrace/timetrace 0.7.1 already installed ELSML03UR088T:~ ur088t$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow remote: Enumerating objects: 538058, done. remote: Counting objects: 100% (538020/538020), done. remote: Compressing objects: 100% (193653/193653), done. remote: Total 529414 (delta 338540), reused 523776 (delta 332914), pack-reused 0 Receiving objects: 100% (529414/529414), 201.98 MiB | 1.45 MiB/s, done. Resolving deltas: 100% (338540/338540), completed with 3969 local objects. From https://github.com/Homebrew/homebrew-core 94260977d2..c6a010d7be master -> origin/master ELSML03UR088T:~ ur088t$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow remote: Enumerating objects: 332303, done. remote: Counting objects: 100% (330282/330282), done. remote: Compressing objects: 100% (96683/96683), done. remote: Total 322241 (delta 229796), reused 317466 (delta 225021), pack-reused 0 Receiving objects: 100% (322241/322241), 120.68 MiB | 1.64 MiB/s, done. Resolving deltas: 100% (229796/229796), completed with 3180 local objects. From https://github.com/Homebrew/homebrew-cask a0b1f7a29e..30b263d39e master -> origin/master ELSML03UR088T:~ ur088t$ brew upgrade timetrace Warning: dominikbraun/timetrace/timetrace 0.7.1 already installed ELSML03UR088T:~ ur088t$

This seems to be an Homebrew issue not related to timetrace. See here: https://github.com/Homebrew/brew/issues/9420

dominikbraun commented 3 years ago

Going to close this since timetrace seems to work fine and we didn't have any complaints anymore. Feel free to re-open this issue or file a new one if you have problems!