nazrinharris / pecunia

Massively ambitious personal finance app.
1 stars 0 forks source link

`requireValue` on `PecuniaDB` throws error when newly installed app and registered a new account #177

Open nazrinharris opened 2 months ago

nazrinharris commented 2 months ago

This is the error stack when I registered a new account right after a brand new install (so I uninstall first to remove all data). This is like shown in MonthlyTxnModule. It shows the gray box (would be red if in debug mode)

I/flutter (25889): (getAllAccountsProvider) : StateError : Bad state: Tried to call `requireValue` on an `AsyncValue` that has no value: AsyncLoading<PecuniaDriftDB>()
I/flutter (25889): (getTxnsOverPeriodProvider) : StateError : Bad state: Tried to call `requireValue` on an `AsyncValue` that has no value: AsyncLoading<PecuniaDriftDB>()
I/flutter (25889): (getTxnsOverPeriodProvider) : StateError : Bad state: Tried to call `requireValue` on an `AsyncValue` that has no value: AsyncLoading<PecuniaDriftDB>()
I/flutter (25889): (getAllTransactionsProvider) : StateError : Bad state: Tried to call `requireValue` on an `AsyncValue` that has no value: AsyncLoading<PecuniaDriftDB>()
I/flutter (25889): (getAllTxnsAndAccountsProvider) : ParallelWaitError<(List<Transaction>?, List<Account>?), (AsyncError?, AsyncError?)> : ParallelWaitError
I/flutter (25889): (pecuniaDBProvider) : AsyncData<PecuniaDriftDB>(value: Instance of 'PecuniaDriftDB')...
I/flutter (25889): type 'StateError' is not a subtype of type 'Failure' in type cast
I/flutter (25889): #0      MonthlyTxnModule.build (package:pecunia/presentation/widgets/transactions/monthly_txn_module.dart:33)
I/flutter (25889): #1      _ConsumerState.build (package:flutter_riverpod/src/consumer.dart:476)
I/flutter (25889): #2      StatefulElement.build (package:flutter/src/widgets/framework.dart:5592)
I/flutter (25889): #3      ConsumerStatefulElement.build (package:flutter_riverpod/src/consumer.dart:539)
I/flutter (25889): #4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5480)
I/flutter (25889): #5      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643)
I/flutter (25889): #6      Element.rebuild (package:flutter/src/widgets/framework.dart:5196)
I/flutter (25889): #7      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2904)
I/flutter (25889): #8      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:989)
I/flutter (25889): #9      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:448)
I/flutter (25889): #10     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1386)
I/flutter (25889): #11     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1311)
I/flutter (25889): #12     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1169)
I/flutter (25889): #13     _invoke (dart:ui/hooks.dart:312)
I/flutter (25889): #14     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:399)
I/flutter (25889): #15     _drawFrame (dart:ui/hooks.dart:283)
I/flutter (25889): Another exception was thrown: type 'StateError' is not a subtype of type 'Failure' in type cast

There is also another different error, but likely the same issue. The same MonthlyTxnModule would show unknown error occurred, but at that point I don't really have the access to the debug. And it sometimes happen sometimes not.

This is likely a race condition issue. I might need to rethink initialization.

nazrinharris commented 2 months ago

My guesstimation is that the app navigates to the MainScreen before PecuniaDB can truly initialize. Which I thought was fixed in an uncommited fix for #147, but it seems I am wrong.

But a little aha moment while writing, the initialization improvements are only from EntryScreen so mayhaps perchance the problem lies in RegisterScreen?