Skip to content

Commit

Permalink
Throw an exception instead of the character when the scanner finds an…
Browse files Browse the repository at this point in the history
… invalid character. (#233)
  • Loading branch information
GunnarFarneback committed Jun 28, 2024
1 parent 37e287e commit 3b2b353
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/scanner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,9 @@ function fetch_more_tokens(stream::TokenStream)
elseif check_plain(stream)
fetch_plain(stream)
else
# TODO: Throw a meaningful exception.
throw(c)
throw(ScannerError(nothing, nothing,
"while scanning for the next token, found character '$c' that cannot start any token",
get_mark(stream)))
end
end

Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ end
dicttype=() -> 3.0 # wrong type
)

@test_throws YAML.ScannerError YAML.load("x: %")
if VERSION >= v"1.8"
@test_throws "found character '%' that cannot start any token" YAML.load("x: %")
end

# issue 81
dict_content = ["key1" => [Dict("subkey1" => "subvalue1", "subkey2" => "subvalue2"), Dict()], "key2" => "value2"]
order_one = OrderedDict(dict_content...)
Expand Down

0 comments on commit 3b2b353

Please sign in to comment.