Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load empty YAML file #143

Closed
Paalon opened this issue Jun 3, 2024 · 5 comments
Closed

Cannot load empty YAML file #143

Paalon opened this issue Jun 3, 2024 · 5 comments

Comments

@Paalon
Copy link
Contributor

Paalon commented Jun 3, 2024

The following gives an error:

using YAML

YAML.load("")
ERROR: AssertionError: typeof(forward!(composer.input)) == DocumentStartEvent
Stacktrace:
 [1] compose_document(composer::YAML.Composer)
   @ YAML ~/.julia/packages/YAML/U6OOW/src/composer.jl:49
 [2] compose(events::YAML.EventStream)
   @ YAML ~/.julia/packages/YAML/U6OOW/src/composer.jl:38
 [3] load(ts::YAML.TokenStream, constructor::YAML.Constructor)
   @ YAML ~/.julia/packages/YAML/U6OOW/src/YAML.jl:38
 [4] load(ts::YAML.TokenStream, more_constructors::Nothing, multi_constructors::Dict{…}; dicttype::Type{…}, constructorType::typeof(YAML.SafeConstructor))
   @ YAML ~/.julia/packages/YAML/U6OOW/src/YAML.jl:44
 [5] load
   @ ~/.julia/packages/YAML/U6OOW/src/YAML.jl:44 [inlined]
 [6] load (repeats 3 times)
   @ ~/.julia/packages/YAML/U6OOW/src/YAML.jl:47 [inlined]
 [7] load(::String)
   @ YAML ~/.julia/packages/YAML/U6OOW/src/YAML.jl:88
 [8] top-level scope
   @ REPL[8]:1
Some type information was truncated. Use `show(err)` to see complete types.

Empty YAML file is a valid YAML file.

@Paalon
Copy link
Contributor Author

Paalon commented Jun 3, 2024

Maybe same reason to #129

@Paalon
Copy link
Contributor Author

Paalon commented Jun 3, 2024

Result of empty YAML from YPaste Interactive Parser:
スクリーンショット 2024-06-03 19 40 39

@Paalon
Copy link
Contributor Author

Paalon commented Jun 13, 2024

I noticed that this is not a bug because we can't get first document from 0 documents. It's same as [][begin] gives BoundsError in Julia. However this is not user-friendly API name. See #145.

@GunnarFarneback
Copy link
Contributor

The error is of course accidental and not helpful at all. But the user-friendly solution would be to just return a nothing for a file without a document.

@GunnarFarneback
Copy link
Contributor

Regardless of the philosophy around load of a file with no document, this shouldn't error:

julia> YAML.load_all("#")
ERROR: AssertionError: forward!(composer.input) isa DocumentStartEvent

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

No branches or pull requests

3 participants