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

Abierto Apto para principiantes
#430 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
android, kotlin
Área
mobile

Línea de trabajo

Empieza con widget/CategoryTimeWidgetUpdater.kt, especialmente con parseCategories en las líneas 420–447, y compara su tratamiento con parseEventsJSON y parseBucketsJSON. Ejecuta la prueba fallida queryErrorObjectIsAFailureNotZeroMinutes en CategoryTimeWidgetUpdaterTest; el trabajo estará hecho cuando el objeto de error se propague como un fallo mientras que un array realmente vacío siga representando que no hay categorías, lo que permite que onUpdateFailed conserve los totales mostrados.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Kotlin
Estrellas
291
Forks
73
Merge medio
4 d 5 h
PR fusionados (30 d)
27

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ActivityWatch/aw-android

Todos los issues de ActivityWatch/aw-android

Issues similares

Más issues de Kotlin

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.