Merge branch 'remove-invalid-accounts' into 'main'

remove things that fail to deserialize

See merge request veilid/veilidchat!47
This commit is contained in:
Christien Rioux 2025-04-09 18:24:32 -04:00
commit b835e10200
4 changed files with 36 additions and 9 deletions

View File

@ -40,6 +40,13 @@ sealed class LocalAccount with _$LocalAccount {
required String name,
}) = _LocalAccount;
factory LocalAccount.fromJson(dynamic json) =>
_$LocalAccountFromJson(json as Map<String, dynamic>);
factory LocalAccount.fromJson(dynamic json) {
try {
return _$LocalAccountFromJson(json as Map<String, dynamic>);
// Need to catch any errors here too
// ignore: avoid_catches_without_on_clauses
} catch (e, st) {
throw Exception('invalid local account: $e\n$st');
}
}
}

View File

@ -23,6 +23,13 @@ sealed class UserLogin with _$UserLogin {
required Timestamp lastActive,
}) = _UserLogin;
factory UserLogin.fromJson(dynamic json) =>
_$UserLoginFromJson(json as Map<String, dynamic>);
factory UserLogin.fromJson(dynamic json) {
try {
return _$UserLoginFromJson(json as Map<String, dynamic>);
// Need to catch any errors here too
// ignore: avoid_catches_without_on_clauses
} catch (e, st) {
throw Exception('invalid user login: $e\n$st');
}
}
}

View File

@ -6,6 +6,9 @@ import 'package:async_tools/async_tools.dart';
import 'package:meta/meta.dart';
import 'package:veilid/veilid.dart';
import '../veilid_support.dart';
import 'veilid_log.dart';
Future<T> tableScope<T>(
String name, Future<T> Function(VeilidTableDB tdb) callback,
{int columnCount = 1}) async {
@ -48,11 +51,20 @@ abstract mixin class TableDBBackedJson<T> {
/// Load things from storage
@protected
Future<T?> load() async {
final obj = await tableScope(tableName(), (tdb) async {
final objJson = await tdb.loadStringJson(0, tableKeyName());
return valueFromJson(objJson);
});
return obj;
try {
final obj = await tableScope(tableName(), (tdb) async {
final objJson = await tdb.loadStringJson(0, tableKeyName());
return valueFromJson(objJson);
});
return obj;
} on Exception catch (e, st) {
veilidLoggy.debug(
'Unable to load data from table store: '
'${tableName()}:${tableKeyName()}',
e,
st);
return null;
}
}
/// Store things to storage

View File

@ -69,6 +69,7 @@ void processLog(VeilidLog log) {
}
void initVeilidLog(bool debugMode) {
// Always allow LOG_TRACE option
// ignore: do_not_use_environment
const isTrace = String.fromEnvironment('LOG_TRACE') != '';
LogLevel logLevel;