What's wrong
DocumentStore.Load says it returns every failure rather than throwing, because an exception that escapes a draw call takes the application down. An empty file breaks that promise:
Coder.Editor/DocumentStore.cs:68 calls deserializer.Deserialize(yaml).
- That call is guarded only by
catch (YamlException) (line 70) and catch (InvalidOperationException) (line 76).
Coder/Serialization/YamlDeserializer.cs:39 starts with ArgumentException.ThrowIfNullOrWhiteSpace(yaml);.
ArgumentException is neither of the caught types, so it propagates out of Load.
- The caller,
CoderEditorApp.Open (Coder.Editor/CoderEditorApp.cs:589), is called from the ImGui menu, both File > Open (line 348) and the recent-files list (line 367). Neither caller has a try/catch.
Failure scenario
Open a 0-byte file, or a file containing only " \n", from File > Open or from the recent-files list. A 0-byte file is an ordinary thing to meet: an interrupted save or a newly created file leaves one. Load throws System.ArgumentException instead of returning DocumentResult.Failed(...), and the exception escapes the frame.
This was confirmed against the built ktsu.Coder.dll: Deserialize("") and Deserialize(" \n") both throw System.ArgumentException. The existing tests, CoderEditorAppTests.Open_ReportsAMissingFile and Open_ReportsAFileThatIsNotADocument, don't cover empty content.
Suggested fix
- In
DocumentStore.Load, check string.IsNullOrWhiteSpace(yaml) before deserializing, and return DocumentResult.Failed($"{path} is empty."). Alternatively, add an ArgumentException catch alongside the other two.
- Add
Open_ReportsAnEmptyFile, covering both empty and whitespace-only content, and assert that Open returns false and sets Status.
What's wrong
DocumentStore.Loadsays it returns every failure rather than throwing, because an exception that escapes a draw call takes the application down. An empty file breaks that promise:Coder.Editor/DocumentStore.cs:68callsdeserializer.Deserialize(yaml).catch (YamlException)(line 70) andcatch (InvalidOperationException)(line 76).Coder/Serialization/YamlDeserializer.cs:39starts withArgumentException.ThrowIfNullOrWhiteSpace(yaml);.ArgumentExceptionis neither of the caught types, so it propagates out ofLoad.CoderEditorApp.Open(Coder.Editor/CoderEditorApp.cs:589), is called from the ImGui menu, both File > Open (line 348) and the recent-files list (line 367). Neither caller has a try/catch.Failure scenario
Open a 0-byte file, or a file containing only
" \n", from File > Open or from the recent-files list. A 0-byte file is an ordinary thing to meet: an interrupted save or a newly created file leaves one.LoadthrowsSystem.ArgumentExceptioninstead of returningDocumentResult.Failed(...), and the exception escapes the frame.This was confirmed against the built
ktsu.Coder.dll:Deserialize("")andDeserialize(" \n")both throwSystem.ArgumentException. The existing tests,CoderEditorAppTests.Open_ReportsAMissingFileandOpen_ReportsAFileThatIsNotADocument, don't cover empty content.Suggested fix
DocumentStore.Load, checkstring.IsNullOrWhiteSpace(yaml)before deserializing, and returnDocumentResult.Failed($"{path} is empty."). Alternatively, add anArgumentExceptioncatch alongside the other two.Open_ReportsAnEmptyFile, covering both empty and whitespace-only content, and assert thatOpenreturnsfalseand setsStatus.