Widget shows 0 h 0 m when the category query fails, overwriting good totals

Open Beginner friendly
#430 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Start with widget/CategoryTimeWidgetUpdater.kt, especially parseCategories at lines 420–447, and compare its handling with parseEventsJSON and parseBucketsJSON. Run the failing queryErrorObjectIsAFailureNotZeroMinutes test in CategoryTimeWidgetUpdaterTest; done means the error object propagates as a failure while a genuine empty array still represents no categories, allowing onUpdateFailed to preserve the displayed totals.

Written by the indexing model from the issue text.

Description

bug

When the native query fails, the home-screen widget shows 0 h 0 m for today and replaces totals that were already rendered.

androidQuery returns {"error": "Something went wrong when trying to query: …"} when the query fails (aw-server-rust aw-server/src/android/mod.rs, create_error_object). This happens, for example, when the aw-watcher-android bucket has been deleted, when a category regex doesn't compile, or when the datastore errors. CategoryTimeWidgetUpdater.parseCategories (widget/CategoryTimeWidgetUpdater.kt:420-447) passes that string to JSONArray(...), which throws. The exception is caught and the function returns the same empty list as a genuine "[]". loadData therefore counts as a success, and the widget renders zero minutes with a fresh timestamp. The KDoc of onUpdateFailed says a load failure renders "no data yet" and keeps the data already shown; that path is never reached.

Failing test (CategoryTimeWidgetUpdaterTest):

@Test
fun queryErrorObjectIsAFailureNotZeroMinutes() {
    // what androidQuery returns when the query fails
    val error = """{"error":"Something went wrong when trying to query: x"}"""
    assertThrows(Exception::class.java) { CategoryTimeWidgetUpdater.parseCategories(error) }
}

It fails today because parseCategories returns emptyList(), the same result as for "[]".

Fix direction: recognise the error object (as parseEventsJSON / parseBucketsJSON already do for getEvents / getBuckets) and let it propagate, so onUpdateFailed runs.

NotifyWorker has the same parse pattern with a different symptom; filed separately as #431.

Priority: medium (users see wrong totals). This repo only has a priority: high label, so no priority label is set.

fingerprint: widget/CategoryTimeWidgetUpdater.kt — androidQuery error object rendered as 0 minutes

Found by code review on master 3b820d61. I verified the trigger path against aw-server-rust 67432e66. I have not run it on a device.

Dominant language
Kotlin
Stars
291
Forks
73
Avg merge
4d 5h
Merged PRs (30d)
27

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ActivityWatch/aw-android

All issues in ActivityWatch/aw-android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.