Skip to content

Report an empty document as empty rather than unparseable [patch] - #200

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/121-empty-document
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/121-empty-document

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #121

What changed

The crash the issue describes no longer happens on main. b256a0e widened DocumentStore.Load to catch (Exception ex) when (ex is not OutOfMemoryException), so the ArgumentException from Deserialize("") doesn't escape the frame any more. What's left is the message. A 0-byte file, which an interrupted save leaves behind, was reported as "… is not a document this editor understands: Value cannot be null or whitespace (Parameter 'yaml')".

This PR implements the issue's suggested fix:

  • Load returns DocumentResult.Failed("{path} is empty.") for empty or whitespace-only content before it calls the deserializer.
  • Open_ReportsAnEmptyFile covers "" and " \n". It asserts that Open returns false, that the status says the file is empty, and that no document path is set.

Verification

  • With the DocumentStore change reverted, both new test cases fail on the status message. With it in place, they pass.
  • Full Coder.Test suite: 1102 passed, 0 failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ACXyQBPWSqFJuF51Mx6FNh


Generated by Claude Code

The broad catch added in b256a0e already keeps an empty file from
crashing the editor, but it reported the deserializer's argument
exception: "is not a document this editor understands: Value cannot be
null or whitespace". Check for empty or whitespace-only content before
deserializing and say the file is empty, and pin both cases in
Open_ReportsAnEmptyFile.

Fixes #121

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ACXyQBPWSqFJuF51Mx6FNh
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 3a8e2cd into main Oct 9, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/121-empty-document branch October 9, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant