Skip to content

Commit d430d1b

Browse files
authored
Fix legacy production sheet saving and loading errors (#165)
This fixes #159; I expected `CanBeNull` to be accurate, and in this case, it wasn't. I also made the reader more forgiving; now it'll continue to read the rest of the object even if it fails to read one of the non-constructor properties.
2 parents ec4f968 + d0cdc3d commit d430d1b

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

Yafc.Model/Serialization/ErrorCollector.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public void Exception(Exception exception, string message, ErrorSeverity errorSe
4646
else if (exception is NotSupportedException notSupportedException) {
4747
s += notSupportedException.Message;
4848
}
49+
else if (exception is InvalidOperationException unexpectedNull) {
50+
s += unexpectedNull.Message;
51+
}
4952
else {
5053
s += exception.GetType().Name;
5154
}

Yafc.Model/Serialization/SerializationMap.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,12 @@ public static void PopulateFromJson(T obj, ref Utf8JsonReader reader, Deserializ
315315
}
316316
else {
317317
_ = reader.Read();
318-
property.DeserializeFromJson(obj, ref reader, allObjects);
318+
try {
319+
property.DeserializeFromJson(obj, ref reader, allObjects);
320+
}
321+
catch (InvalidOperationException ex) {
322+
allObjects.Exception(ex, "Encountered an unexpected value when reading the project file", ErrorSeverity.MajorDataLoss);
323+
}
319324
}
320325
_ = reader.Read();
321326
}

Yafc.Model/Serialization/ValueSerializers.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ public override void WriteToJson(Utf8JsonWriter writer, PageReference? value) {
245245
public override void WriteToUndoSnapshot(UndoSnapshotBuilder writer, PageReference? value) {
246246
writer.WriteManagedReference(value);
247247
}
248+
249+
public override bool CanBeNull => true;
248250
}
249251

250252
internal class TypeSerializer : ValueSerializer<Type> {

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Date: soon
2222
- Fix that returning to the Welcome Screen could break the panels in the main window.
2323
- Make horizontal scrollbar clickable/draggable.
2424
- Scroll down/up exactly one page with page down/up keys
25+
- Fix saving and loading errors with legacy production summaries.
2526
Internal changes:
2627
- Initial window size is now separate from the minimal window size.
2728
----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)