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

未关闭 适合新手
#430 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, kotlin
领域
mobile

调研方向

从widget/CategoryTimeWidgetUpdater.kt开始,重点查看第420–447行的parseCategories,并将其处理方式与parseEventsJSON和parseBucketsJSON进行比较。在CategoryTimeWidgetUpdaterTest中运行失败的测试queryErrorObjectIsAFailureNotZeroMinutes;当错误对象作为失败传递,而真正的空数组仍表示没有类别,从而使onUpdateFailed能够保留显示的总计时,即为完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Kotlin
星标
291
派生
73
平均合并
4 天 5 小时
30 天内合并 PR
27

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ActivityWatch/aw-android 的其他 Issue

查看 ActivityWatch/aw-android 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。