exception handling work

This commit is contained in:
Christien Rioux 2024-08-03 11:50:33 -05:00
parent 1b7ac31085
commit cbac96de99
9 changed files with 24 additions and 21 deletions

View File

@ -56,7 +56,7 @@ class AccountRecordCubit extends DefaultDHTRecordCubit<AccountRecordState> {
Future<void> _updateAccountAsync( Future<void> _updateAccountAsync(
AccountSpec accountSpec, Future<void> Function() onSuccess) async { AccountSpec accountSpec, Future<void> Function() onSuccess) async {
var changed = false; var changed = false;
await record.eventualUpdateProtobuf(proto.Account.fromBuffer, (old) async { await record?.eventualUpdateProtobuf(proto.Account.fromBuffer, (old) async {
changed = false; changed = false;
if (old == null) { if (old == null) {
return null; return null;

View File

@ -41,7 +41,7 @@ class WaitingInvitationsBlocMapCubit extends BlocMapCubit<TypedKey,
@override @override
Future<void> close() async { Future<void> close() async {
await _singleInvitationStatusProcessor.unfollow(); await _singleInvitationStatusProcessor.close();
await super.close(); await super.close();
} }

View File

@ -209,7 +209,7 @@ class ConversationCubit extends Cubit<AsyncValue<ConversationState>> {
return; return;
} }
serialFuture((this, _sfUpdateAccountChange), () async { serialFuture((this, _sfUpdateAccountChange), () async {
await cubit.record.eventualUpdateProtobuf(proto.Conversation.fromBuffer, await cubit.record?.eventualUpdateProtobuf(proto.Conversation.fromBuffer,
(old) async { (old) async {
if (old == null || old.profile == account.profile) { if (old == null || old.profile == account.profile) {
return null; return null;

View File

@ -80,7 +80,7 @@ class MenuItemWidget extends StatelessWidget {
), ),
onPressed: footerCallback), onPressed: footerCallback),
], ],
), ).paddingAll(2),
); );
@override @override

View File

@ -39,7 +39,7 @@ class AvatarWidget extends StatelessWidget {
width: _size, width: _size,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
border: _scaleConfig.preferBorders border: _scaleConfig.useVisualIndicators
? Border.all( ? Border.all(
color: _borderColor, color: _borderColor,
width: 1 * (_size ~/ 32 + 1), width: 1 * (_size ~/ 32 + 1),

View File

@ -116,7 +116,7 @@ Widget buildProgressIndicator() => Builder(builder: (context) {
return FittedBox( return FittedBox(
fit: BoxFit.scaleDown, fit: BoxFit.scaleDown,
child: SpinKitFoldingCube( child: SpinKitFoldingCube(
color: scale.tertiaryScale.primary, color: scale.tertiaryScale.border,
size: 80, size: 80,
)); ));
}); });

View File

@ -52,8 +52,11 @@ class DefaultDHTRecordCubit<T> extends DHTRecordCubit<T> {
Future<void> refreshDefault() async { Future<void> refreshDefault() async {
await initWait(); await initWait();
final rec = record;
final defaultSubkey = record.subkeyOrDefault(-1); if (rec != null) {
await refresh([ValueSubkeyRange(low: defaultSubkey, high: defaultSubkey)]); final defaultSubkey = rec.subkeyOrDefault(-1);
await refresh(
[ValueSubkeyRange(low: defaultSubkey, high: defaultSubkey)]);
}
} }
} }

View File

@ -26,7 +26,7 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
// Do record open/create // Do record open/create
while (!cancel.isCompleted) { while (!cancel.isCompleted) {
try { try {
_record = await open(); record = await open();
_wantsCloseRecord = true; _wantsCloseRecord = true;
break; break;
} on DHTExceptionNotAvailable { } on DHTExceptionNotAvailable {
@ -49,7 +49,7 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
) async { ) async {
// Make initial state update // Make initial state update
try { try {
final initialState = await initialStateFunction(_record); final initialState = await initialStateFunction(record!);
if (initialState != null) { if (initialState != null) {
emit(AsyncValue.data(initialState)); emit(AsyncValue.data(initialState));
} }
@ -57,7 +57,7 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
emit(AsyncValue.error(e)); emit(AsyncValue.error(e));
} }
_subscription = await _record.listen((record, data, subkeys) async { _subscription = await record!.listen((record, data, subkeys) async {
try { try {
final newState = await stateFunction(record, subkeys, data); final newState = await stateFunction(record, subkeys, data);
if (newState != null) { if (newState != null) {
@ -68,17 +68,17 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
} }
}); });
await watchFunction(_record); await watchFunction(record!);
} }
@override @override
Future<void> close() async { Future<void> close() async {
await initWait(cancelValue: true); await initWait(cancelValue: true);
await _record.cancelWatch(); await record?.cancelWatch();
await _subscription?.cancel(); await _subscription?.cancel();
_subscription = null; _subscription = null;
if (_wantsCloseRecord) { if (_wantsCloseRecord) {
await _record.close(); await record?.close();
_wantsCloseRecord = false; _wantsCloseRecord = false;
} }
await super.close(); await super.close();
@ -91,10 +91,10 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
for (final skr in subkeys) { for (final skr in subkeys) {
for (var sk = skr.low; sk <= skr.high; sk++) { for (var sk = skr.low; sk <= skr.high; sk++) {
final data = await _record.get( final data = await record!
subkey: sk, refreshMode: DHTRecordRefreshMode.update); .get(subkey: sk, refreshMode: DHTRecordRefreshMode.update);
if (data != null) { if (data != null) {
final newState = await _stateFunction(_record, updateSubkeys, data); final newState = await _stateFunction(record!, updateSubkeys, data);
if (newState != null) { if (newState != null) {
// Emit the new state // Emit the new state
emit(AsyncValue.data(newState)); emit(AsyncValue.data(newState));
@ -108,13 +108,13 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
} }
} }
DHTRecord get record => _record; // DHTRecord get record => _record;
@protected @protected
final WaitSet<void, bool> initWait = WaitSet(); final WaitSet<void, bool> initWait = WaitSet();
StreamSubscription<DHTRecordWatchChange>? _subscription; StreamSubscription<DHTRecordWatchChange>? _subscription;
late DHTRecord _record; DHTRecord? record;
bool _wantsCloseRecord; bool _wantsCloseRecord;
final StateFunction<T> _stateFunction; final StateFunction<T> _stateFunction;
} }

View File

@ -849,7 +849,7 @@ class DHTRecordPool with TableDBBackedJson<DHTRecordPoolAllocations> {
openedRecordInfo.shared.needsWatchStateUpdate = false; openedRecordInfo.shared.needsWatchStateUpdate = false;
} }
} on VeilidAPIException catch (e) { } on VeilidAPIException catch (e) {
// Failed to cancel DHT watch, try again next tick // Failed to update DHT watch, try again next tick
log('Exception in watch update: $e'); log('Exception in watch update: $e');
} }
} }