ActivityWatch / activitywatch

The best free and open-source automated time tracker. Cross-platform, extensible, privacy-focused.
https://activitywatch.net/
Mozilla Public License 2.0
11.44k stars 521 forks source link

Category Builder doesn't work "TypeError: c[f].events is undefined" #905

Closed douglasg14b closed 8 months ago

douglasg14b commented 1 year ago

Describe the bug

Just installed and setup ActivityWatch and after a day of work went to setup categories. Category builder doesn't work, just shows loading perpetually. When it loads, the following error shows in console:

image

Which is thrown from here: https://github.com/ActivityWatch/aw-webui/blob/1f194ff6886d82ac5928e8cb944888d378c54157/src/views/settings/CategoryBuilder.vue#L227

To Reproduce

Unknown, happens every time

Expected behavior

It doesn't fail, and loads categories

Documentation

The date range selection appears to be borked? Inconsistent date offsets/not using UTS everywhere?

  1. Select 18th -> 20th (Today is the 19th) the network request responds with 810 items
  2. Select 18th -> 21st (2 days in the future) the network request returns 999 items
    • It also doesn't fail, and loads a bunch of categories

Additional context

Watchers:

ErikBjare commented 1 year ago

Strange, I don't see how that could happen given the code:

      const words = {};
      for (const event of events) {
        const words_in_event = event.data.title.split(/[\s\-,:()[\]/]/);
        for (const word of words_in_event) {
          if (word.length <= 2 || this.ignored_words.includes(word)) {
            continue;
          }
          if (word in words) {
            words[word].duration += event.duration;
            words[word].events.push(event);
          } else {
            words[word] = {
              word: word,
              duration: event.duration,
              events: [event],
            };
          }
        }
      }

https://github.com/ActivityWatch/aw-webui/blob/1f194ff6886d82ac5928e8cb944888d378c54157/src/views/settings/CategoryBuilder.vue#L218-L236

words should always have a events, and we check if word in words, so... :man_shrugging:

Looks like the code hasn't changed since v0.12.2 either, so probably not something that a newer version would fix.

ErikBjare commented 1 year ago

Maybe there is a strange word in words_in_event? The word.length <= 2 will return false for any non-strings, for example. But split would never do that... Nah, no way.

I played a bit with the code just to try and figure it out, but it all looks right to me... I ended up improving the common string algorithm to also include common bigrams: https://github.com/ActivityWatch/aw-webui/pull/455

Still no clue how this bug could happen though.

douglasg14b commented 1 year ago

I was only able to repro this with a fresh setup, now that there is more than a day of data it doesn't seem to crop up 🤔

@ErikBjare I would recommend some defensive programming around this, and validating that the events property of each value actually exists wherever it is they are pulled or created from. And then logging contextual errors if it's missing. This can greatly assist with finding the bug source in the future.

vimrookie commented 1 year ago

Any solution? I installed it yesterday as a new user, and this bug is also happening to me.

JaydonZhao commented 10 months ago

Hi, marvelous developer, I installed AcitvityWatch earlier today, and I have the same issue: Category builder doesn't work, just shows loading perpetually. Is there any solution for it as of now?

Qemuel8 commented 9 months ago

So the way i fixed this could also solve it for other. -Go to category builder. -Press Show Options. -Select a different host name.

as i understand my issue was related to having an old watcher that i wasnt using and was deleted but was still showing in the list of hosts. Picking the new host solved the problem for me.

ErikBjare commented 9 months ago

@Qemuel8 Good observation!

The categorization helper currently assumes which hostname is the target, but it can be changed by clicking "Show options" and choosing the correct host in the dropdown.

I'll work on these bad assumptions.

ErikBjare commented 8 months ago

Fixed now, see https://github.com/ActivityWatch/activitywatch/issues/965#issuecomment-1817986172

Thanks for reporting!