Skip to content

OpenApiYamlReader.Read inconsistent behavior for errors #3056

Description

Describe the bug
OpenApiYamlReader.Read throws and exception in some error cases and returns a ReadResult in others. I expect it to always return a ReadResult. A ReadResult is already something that can describe a failure.

For instance, given an empty document:

using var stream = new MemoryStream();
new OpenApiYamlReader().Read(stream, new Uri("https://example.com/"), new OpenApiReaderSettings());

It throws:

System.InvalidOperationException : No documents found in the YAML stream.
   at Microsoft.OpenApi.YamlReader.OpenApiYamlReader.LoadJsonNodesFromYamlDocument(TextReader input)
   at Microsoft.OpenApi.YamlReader.OpenApiYamlReader.Read(MemoryStream input, Uri location, OpenApiReaderSettings settings)

I expected it it return a ReadResult describing the error.

OpenApi File To Reproduce
An empty file.

Expected behavior
It returns a ReadResult with Document = null and a Diagnostic describing the problem.

Alternatively, when the choice between throwing an exception or returning a ReadResult is by design, this should be documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions