gracefully catch errors when parsing membership state

This commit is contained in:
Henry Hiles 2026-10-12 10:36:41 -04:00
commit 30a5fa100c
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
3 changed files with 9 additions and 14 deletions

View file

@ -17,11 +17,7 @@ import "package:nexus/models/content/topic.dart";
import "package:nexus/models/content/sticker.dart";
import "package:nexus/models/content/history_visibility.dart";
class Content {
final Error? parseError;
const Content({this.parseError});
class const Content({final String? parseError, final StackTrace? stackTrace}) {
factory Content.fromJson(Map<String, dynamic> json) => const Content();
Map<String, dynamic> toJson() => {};
@ -35,9 +31,8 @@ class Content {
.firstWhereOrNull((eventType) => eventType.type == type)
?.contentFromJson ??
Content.fromJson)(json);
} catch (error) {
if (error is Error) return Content(parseError: error);
rethrow;
} catch (error, stackTrace) {
return Content(parseError: error.toString(), stackTrace: stackTrace);
}
}
}
@ -65,5 +60,5 @@ enum EventType(
name("m.room.name", NameContent.fromJson),
reaction("m.reaction", ReactionContent.fromJson),
pinnedEvents("m.room.pinned_events", PinnedEventsContent.fromJson),
message("m.room.message", MessageContent.fromJson);
message("m.room.message", MessageContent.fromJson),
}

View file

@ -58,16 +58,16 @@ class const Event({
replyTo: replyToFromJson(getContentFromJson(json)),
pmp: json["content"]?["com.beeper.per_message_profile"] == null
? null
: Profile.fromJsonWithCatch(
: .fromJsonWithCatch(
json["content"]?["com.beeper.per_message_profile"],
),
content: Content.fromEventJson(
content: .fromEventJson(
getContentFromJson(json),
json["decrypted_type"] ?? json["type"],
),
previousContent: json["unsigned"]?["prev_content"] == null
? null
: Content.fromEventJson(
: .fromEventJson(
json["unsigned"]?["prev_content"],
json["decrypted_type"] ?? json["type"],
),