Skip to content

Opening an empty or whitespace-only .coder.yaml throws ArgumentException out of DocumentStore.Load and can take the editor down #121

Description

@matt-edmondson

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions