gracefully catch errors when parsing membership state
This commit is contained in:
parent
f198888635
commit
30a5fa100c
3 changed files with 9 additions and 14 deletions
|
|
@ -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),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -84,11 +84,11 @@ class const EventRenderer(
|
|||
final child = event.redactedBy != null || event.relationType == "m.replace"
|
||||
? null
|
||||
: switch (event.content) {
|
||||
Content(:final parseError?) => Row(
|
||||
Content(:final parseError?, :final stackTrace) => Row(
|
||||
children: [
|
||||
ErrorDialog(
|
||||
"An error occurred while parsing event ${event.eventId}:\n$parseError",
|
||||
parseError.stackTrace,
|
||||
stackTrace,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
Loading…
Reference in a new issue