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

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

View file

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

View file

@ -402,11 +402,13 @@ class DHTRecordPool with TableDBBackedJson<DHTRecordPoolAllocations> {
recordDescriptor =
await dhtctx.openDHTRecord(recordKey, writer: writer);
break;
} on VeilidAPIExceptionTryAgain {
throw const DHTExceptionNotAvailable();
} on VeilidAPIExceptionKeyNotFound {
await asyncSleep();
retry--;
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) {
addError(e, st);
emit(DHTShortArrayBusyState<T>(AsyncValue.error(e, st)));
return;
}
@ -96,8 +97,9 @@ class DHTShortArrayCubit<T> extends Cubit<DHTShortArrayBusyState<T>>
}
emit(AsyncValue.data(newState));
setRefreshed();
} on Exception catch (e) {
emit(AsyncValue.error(e));
} on Exception catch (e, st) {
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 {
emit(AsyncValue.data(await load()));
});
} on Exception catch (e, stackTrace) {
emit(AsyncValue.error(e, stackTrace));
} on Exception catch (e, st) {
addError(e, st);
emit(AsyncValue.error(e, st));
}
}
@ -37,8 +38,9 @@ abstract class AsyncTableDBBackedCubit<T> extends Cubit<AsyncValue<T?>>
await _initWait();
try {
emit(AsyncValue.data(await store(newState)));
} on Exception catch (e, stackTrace) {
emit(AsyncValue.error(e, stackTrace));
} on Exception catch (e, st) {
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 err = avElements.asError;
if (err != null) {
addError(err.error, err.stackTrace);
emit(AsyncValue.error(err.error, err.stackTrace));
return;
}
@ -123,6 +124,7 @@ class TableDBArrayProtobufCubit<T extends GeneratedMessage>
final allItems = (await _array.getRange(start, end)).toIList();
return AsyncValue.data(allItems);
} on Exception catch (e, st) {
addError(e, st);
return AsyncValue.error(e, st);
}
}