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));
}
}