taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

a-failed-query-is-shown-as-an-empty-wallet.md (6043B)


      1 <!--
      2   This file is part of GNU Taler
      3   (C) 2026 Taler Systems S.A.
      4 
      5   GNU Taler is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13   You should have received a copy of the GNU General Public License along with
     14   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 -->
     16 
     17 # A failed query is shown as an empty wallet
     18 
     19 Found by the `api_error_sweep` scenario, which makes one wallet-core call fail
     20 per screen and reads what the screen then says. Four of the ten screens it
     21 sweeps report nothing at all, and two of those four state the failure as a fact
     22 about the user's money.
     23 
     24 **Severity: moderate.** No money is at risk, but the wallet tells the user
     25 something untrue about their own wallet, and the only trace is in the log.
     26 
     27 ## What happens
     28 
     29 The sweep injects `WALLET_UNEXPECTED_EXCEPTION` into one operation and then
     30 opens the screen that calls it:
     31 
     32 | operation | screen | what it shows |
     33 | --- | --- | --- |
     34 | `getBalances` | main screen | the error, with "Export error diagnostics" |
     35 | `getTransactionsV2` | transaction list | the error |
     36 | `listBankAccounts` | Settings → Bank accounts | the error |
     37 | `listDiscounts` | Discounts | the error |
     38 | `listSubscriptions` | Passes | the error |
     39 | `getExchangeTos` | PSP's terms of service | the error, with its own heading |
     40 | `listExchanges` | Settings → Payment services | **nothing** — the list renders |
     41 | `getContacts` | Contacts | **"No contacts yet."** |
     42 | `getDepositWireTypes` | Deposit | **"No bank accounts saved in the wallet"** |
     43 | `getMaxDepositAmount` | Deposit | **nothing** — the account list renders |
     44 | `getMaxPeerPushDebitAmount` | Send | **"€0.00"**, and a "Send €0.00" button |
     45 | `getWithdrawalDetailsForAmount` | Withdraw | **an empty screen** |
     46 | `getCurrencySpecification` | main screen | **nothing** — amounts lose their symbol |
     47 
     48 Six of the thirteen are right: an `ErrorComposable` with the code, the hint and
     49 a way to export diagnostics. The rest are the defect, and three of them are
     50 worse than silence, because they state the failure as a fact about the user:
     51 
     52 * **Deposit** says the user has *no bank accounts*. They may well have
     53   several; the wallet simply could not ask.
     54 * **Contacts** says *"No contacts yet."*, the same way.
     55 * **Send** says the user can send *nothing*, with a disabled-looking
     56   "Send €0.00", on a wallet holding €9.87.
     57 
     58 ## Why
     59 
     60 Both are the same shape — a nullable result, an error that only reaches the
     61 log, and a caller that reads `null` as "nothing there":
     62 
     63 ```kotlin
     64 // wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt:166
     65 suspend fun getDepositWireTypes(…): GetDepositWireTypesResponse? {
     66     var result: GetDepositWireTypesResponse? = null
     67     api.request("getDepositWireTypes", …)
     68         .onError { Log.e(TAG, "Error getDepositWireTypes $it") }
     69         .onSuccess { result = it }
     70     return result
     71 }
     72 ```
     73 
     74 ```kotlin
     75 // wallet/src/main/java/net/taler/wallet/peer/PeerManager.kt:215
     76 private suspend fun getMaxPeerPushDebitAmount(…): GetMaxPeerPushDebitAmountResponse? {
     77     var response: GetMaxPeerPushDebitAmountResponse? = null
     78     api.request("getMaxPeerPushDebitAmount", …)
     79         .onError { error -> Log.e(TAG, "got getMaxPeerPushDebitAmount error result $error") }
     80         .onSuccess { response = it }
     81     return response
     82 }
     83 ```
     84 
     85 `PeerManager` alone has nine error handlers whose whole body is a `Log` call;
     86 `grep -n 'onError' wallet/src/main/java/net/taler/wallet/*/*Manager.kt` shows
     87 the shape across the rest.
     88 
     89 The `listExchanges` silence is the same defect as
     90 [`add-payment-service-fails-silently.md`](add-payment-service-fails-silently.md)
     91 seen from the other side: that finding is about `ExchangeManager` publishing
     92 error channels nobody reads, and this is what the user sees when one of them
     93 fires. The empty withdrawal prompt is
     94 [`unreachable-host-leaves-blank-retrying-purchase.md`](unreachable-host-leaves-blank-retrying-purchase.md),
     95 reached without a proxy — one injected error is enough.
     96 
     97 ## Reproduce by hand
     98 
     99 Needs a debug build with **Developer mode** on, and a balance.
    100 
    101 1. Share this URI into the wallet (it fails the next four `getDepositWireTypes`
    102    calls with code 7001):
    103 
    104    ```bash
    105    adb shell am start -a android.intent.action.VIEW -d \
    106      'taler+http://dev-experiment/api-error?operation=getDepositWireTypes&detail=eyJjb2RlIjogNzAwMSwgImhpbnQiOiAiaW5qZWN0ZWQifQ&count=4'
    107    ```
    108 
    109    (`detail` is base64url JSON: `{"code": 7001, "hint": "injected"}`.)
    110 
    111 2. On the main screen tap **Deposit**. The screen says "No bank accounts saved
    112    in the wallet".
    113 3. `adb logcat | grep getDepositWireTypes` shows the real reason.
    114 4. The same with `operation=getMaxPeerPushDebitAmount` and the **Send**
    115    button: the screen offers €0.00.
    116 
    117 ## Reproduce with the simulator
    118 
    119 ```bash
    120 ssh root@tripwire.taler.net
    121 cd /opt/taler-sim/driver
    122 python3 ../findings/repro_failed_query_empty_state.py
    123 SIM_WORKER=4 python3 suite.py api_error_sweep
    124 ```
    125 
    126 The notes of the resulting `suite-w4-*-summary.json` list every screen with
    127 "shows an error: True/False" and what was on it.
    128 
    129 ## Suggested fix
    130 
    131 Distinguish "no data" from "could not ask". The managers already have the
    132 `TalerErrorInfo`; the cheapest change that fixes all four is to give each of
    133 these screens the same `state` treatment the balance list has — `Loading`,
    134 `Success`, `Error` — rather than a nullable payload, so an error renders as
    135 `ErrorComposable` instead of as an empty list or a zero amount.
    136 
    137 Where that is too much, the minimum is: do not claim a fact the wallet does
    138 not have. "No bank accounts saved" and "€0.00" are both assertions; a failed
    139 query should produce neither.