Skip to content

Commit

Permalink
add "some warnings detected" to ParseError printing when all problems…
Browse files Browse the repository at this point in the history
… are warnings (#423)

* try to make warnings clearer

* Apply suggestions from code review

* Update test/hooks.jl
  • Loading branch information
ericphanson authored Jul 24, 2024
1 parent 835a527 commit fd55088
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/parser_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ function ParseError(stream::ParseStream; incomplete_tag=:none, kws...)
end

function Base.showerror(io::IO, err::ParseError)
println(io, "ParseError:")
# Only show the first parse error for now - later errors are often
# misleading due to the way recovery works
i = findfirst(is_error, err.diagnostics)
if isnothing(i)
i = lastindex(err.diagnostics)
level_info = " some warnings detected:"
else
level_info = ""
end
println(io, "ParseError:", level_info)
show_diagnostics(io, err.diagnostics[1:i], err.source)
end

Expand Down
2 changes: 1 addition & 1 deletion test/parser_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ end
catch exc
@test exc isa JuliaSyntax.ParseError
@test sprint(showerror, exc) == """
ParseError:
ParseError: some warnings detected:
# Warning @ somefile.jl:1:2
@(a)
#└─┘ ── parenthesizing macro names is unnecessary"""
Expand Down

0 comments on commit fd55088

Please sign in to comment.