fix DHTRecordCubit open() retry bug

improve error state reporting for cubits
This commit is contained in:
Christien Rioux 2024-08-03 19:12:25 -05:00
parent ab9838f375
commit 83880d79ba
14 changed files with 38 additions and 24 deletions

View File

@ -358,6 +358,7 @@ class ChatComponentCubit extends Cubit<ChatComponentState> {
final asError = avMessagesState.asError; final asError = avMessagesState.asError;
if (asError != null) { if (asError != null) {
addError(asError.error, asError.stackTrace);
return currentState.copyWith( return currentState.copyWith(
unknownUsers: const IMap.empty(), unknownUsers: const IMap.empty(),
messageWindow: AsyncValue.error(asError.error, asError.stackTrace)); messageWindow: AsyncValue.error(asError.error, asError.stackTrace));

View File

@ -180,6 +180,7 @@ class SingleContactMessagesCubit extends Cubit<SingleContactMessagesState> {
_reconciliation = MessageReconciliation( _reconciliation = MessageReconciliation(
output: _reconciledMessagesCubit!, output: _reconciledMessagesCubit!,
onError: (e, st) { onError: (e, st) {
addError(e, st);
emit(AsyncValue.error(e, st)); emit(AsyncValue.error(e, st));
}); });

View File

@ -7,7 +7,6 @@ class EmptyChatWidget extends StatelessWidget {
const EmptyChatWidget({super.key}); const EmptyChatWidget({super.key});
@override @override
// ignore: prefer_expression_function_bodies
Widget build( Widget build(
BuildContext context, BuildContext context,
) { ) {

View File

@ -105,6 +105,7 @@ class ActiveSingleContactChatBlocMapCubit extends BlocMapCubit<TypedKey,
} else { } else {
final (error, stackTrace) = final (error, stackTrace) =
(newValue.asError!.error, newValue.asError!.stackTrace); (newValue.asError!.error, newValue.asError!.stackTrace);
addError(error, stackTrace);
await addState(key, AsyncValue.error(error, stackTrace)); await addState(key, AsyncValue.error(error, stackTrace));
} }
} }

View File

@ -58,6 +58,7 @@ class DHTLogCubit<T> extends Cubit<DHTLogBusyState<T>>
} }
} }
} on Exception catch (e, st) { } on Exception catch (e, st) {
addError(e, st);
emit(DHTLogBusyState(AsyncValue.error(e, st))); emit(DHTLogBusyState(AsyncValue.error(e, st)));
return; return;
} }

View File

@ -35,6 +35,7 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
} }
} }
} on Exception catch (e, st) { } on Exception catch (e, st) {
addError(e, st);
emit(AsyncValue.error(e, st)); emit(AsyncValue.error(e, st));
return; return;
} }
@ -53,8 +54,9 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
if (initialState != null) { if (initialState != null) {
emit(AsyncValue.data(initialState)); emit(AsyncValue.data(initialState));
} }
} on Exception catch (e) { } on Exception catch (e, st) {
emit(AsyncValue.error(e)); addError(e, st);
emit(AsyncValue.error(e, st));
} }
_subscription = await record!.listen((record, data, subkeys) async { _subscription = await record!.listen((record, data, subkeys) async {
@ -63,8 +65,9 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
if (newState != null) { if (newState != null) {
emit(AsyncValue.data(newState)); emit(AsyncValue.data(newState));
} }
} on Exception catch (e) { } on Exception catch (e, st) {
emit(AsyncValue.error(e)); addError(e, st);
emit(AsyncValue.error(e, st));
} }
}); });

View File

@ -402,11 +402,13 @@ class DHTRecordPool with TableDBBackedJson<DHTRecordPoolAllocations> {
recordDescriptor = recordDescriptor =
await dhtctx.openDHTRecord(recordKey, writer: writer); await dhtctx.openDHTRecord(recordKey, writer: writer);
break; break;
} on VeilidAPIExceptionTryAgain {
throw const DHTExceptionNotAvailable();
} on VeilidAPIExceptionKeyNotFound { } on VeilidAPIExceptionKeyNotFound {
await asyncSleep(); await asyncSleep();
retry--; retry--;
if (retry == 0) { if (retry == 0) {
throw DHTExceptionNotAvailable(); throw const DHTExceptionNotAvailable();
} }
} }
} }

View File

@ -46,6 +46,7 @@ class DHTShortArrayCubit<T> extends Cubit<DHTShortArrayBusyState<T>>
} }
} }
} on Exception catch (e, st) { } on Exception catch (e, st) {
addError(e, st);
emit(DHTShortArrayBusyState<T>(AsyncValue.error(e, st))); emit(DHTShortArrayBusyState<T>(AsyncValue.error(e, st)));
return; return;
} }
@ -96,8 +97,9 @@ class DHTShortArrayCubit<T> extends Cubit<DHTShortArrayBusyState<T>>
} }
emit(AsyncValue.data(newState)); emit(AsyncValue.data(newState));
setRefreshed(); setRefreshed();
} on Exception catch (e) { } on Exception catch (e, st) {
emit(AsyncValue.error(e)); addError(e, st);
emit(AsyncValue.error(e, st));
} }
} }

View File

@ -27,8 +27,9 @@ abstract class AsyncTableDBBackedCubit<T> extends Cubit<AsyncValue<T?>>
await _mutex.protect(() async { await _mutex.protect(() async {
emit(AsyncValue.data(await load())); emit(AsyncValue.data(await load()));
}); });
} on Exception catch (e, stackTrace) { } on Exception catch (e, st) {
emit(AsyncValue.error(e, stackTrace)); addError(e, st);
emit(AsyncValue.error(e, st));
} }
} }
@ -37,8 +38,9 @@ abstract class AsyncTableDBBackedCubit<T> extends Cubit<AsyncValue<T?>>
await _initWait(); await _initWait();
try { try {
emit(AsyncValue.data(await store(newState))); emit(AsyncValue.data(await store(newState)));
} on Exception catch (e, stackTrace) { } on Exception catch (e, st) {
emit(AsyncValue.error(e, stackTrace)); addError(e, st);
emit(AsyncValue.error(e, st));
} }
} }

View File

@ -92,6 +92,7 @@ class TableDBArrayProtobufCubit<T extends GeneratedMessage>
final avElements = await _loadElements(_tail, _count); final avElements = await _loadElements(_tail, _count);
final err = avElements.asError; final err = avElements.asError;
if (err != null) { if (err != null) {
addError(err.error, err.stackTrace);
emit(AsyncValue.error(err.error, err.stackTrace)); emit(AsyncValue.error(err.error, err.stackTrace));
return; return;
} }
@ -123,6 +124,7 @@ class TableDBArrayProtobufCubit<T extends GeneratedMessage>
final allItems = (await _array.getRange(start, end)).toIList(); final allItems = (await _array.getRange(start, end)).toIList();
return AsyncValue.data(allItems); return AsyncValue.data(allItems);
} on Exception catch (e, st) { } on Exception catch (e, st) {
addError(e, st);
return AsyncValue.error(e, st); return AsyncValue.error(e, st);
} }
} }

View File

@ -53,10 +53,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: bloc_advanced_tools name: bloc_advanced_tools
sha256: "2b2dd492a350e7192a933d09f15ea04d5d00e7bd3fe2a906fe629cd461ddbf94" sha256: "2ad82be752ab5e983ad9097ed9f334e47a4472c04d5c6b61c99a1bb14a039053"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.1.5" version: "0.1.6"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
@ -718,7 +718,7 @@ packages:
path: "../../../veilid/veilid-flutter" path: "../../../veilid/veilid-flutter"
relative: true relative: true
source: path source: path
version: "0.3.3" version: "0.3.4"
vm_service: vm_service:
dependency: transitive dependency: transitive
description: description:

View File

@ -9,7 +9,7 @@ environment:
dependencies: dependencies:
async_tools: ^0.1.5 async_tools: ^0.1.5
bloc: ^8.1.4 bloc: ^8.1.4
bloc_advanced_tools: ^0.1.5 bloc_advanced_tools: ^0.1.6
charcode: ^1.3.1 charcode: ^1.3.1
collection: ^1.18.0 collection: ^1.18.0
equatable: ^2.0.5 equatable: ^2.0.5
@ -26,7 +26,7 @@ dependencies:
# veilid: ^0.0.1 # veilid: ^0.0.1
path: ../../../veilid/veilid-flutter path: ../../../veilid/veilid-flutter
# dependency_overrides: #dependency_overrides:
# async_tools: # async_tools:
# path: ../../../dart_async_tools # path: ../../../dart_async_tools
# bloc_advanced_tools: # bloc_advanced_tools:

View File

@ -141,10 +141,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: bloc_advanced_tools name: bloc_advanced_tools
sha256: "2b2dd492a350e7192a933d09f15ea04d5d00e7bd3fe2a906fe629cd461ddbf94" sha256: "2ad82be752ab5e983ad9097ed9f334e47a4472c04d5c6b61c99a1bb14a039053"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.1.5" version: "0.1.6"
blurry_modal_progress_hud: blurry_modal_progress_hud:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -19,7 +19,7 @@ dependencies:
badges: ^3.1.2 badges: ^3.1.2
basic_utils: ^5.7.0 basic_utils: ^5.7.0
bloc: ^8.1.4 bloc: ^8.1.4
bloc_advanced_tools: ^0.1.5 bloc_advanced_tools: ^0.1.6
blurry_modal_progress_hud: ^1.1.1 blurry_modal_progress_hud: ^1.1.1
change_case: ^2.1.0 change_case: ^2.1.0
charcode: ^1.3.1 charcode: ^1.3.1