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

add "some warnings detected" to ParseError printing when all problems are warnings #423

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = " some errors detected:"
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
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/hooks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ end
if JuliaSyntax._has_v1_10_hooks
@test err.args[1] isa Meta.ParseError
exc = err.args[1]
@test exc.msg == "ParseError:\n# Error @ none:1:2\n\"\n#└ ── unterminated string literal"
@test exc.msg == "ParseError: some errors detected:\n# Error @ none:1:2\n\"\n#└ ── unterminated string literal"
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
@test exc.detail isa JuliaSyntax.ParseError
@test exc.detail.incomplete_tag === :string
else
Expand Down
8 changes: 4 additions & 4 deletions test/parser_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ end
catch exc
@test exc isa JuliaSyntax.ParseError
@test sprint(showerror, exc) == """
ParseError:
ParseError: some errors detected:
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
# Error @ somefile.jl:1:3
a -- b -- c
# └┘ ── invalid operator"""
@test occursin("Stacktrace:\n", sprint(showerror, exc, catch_backtrace()))
file_url = JuliaSyntax._file_url("somefile.jl")
@test sprint(showerror, exc, context=:color=>true) == """
ParseError:
ParseError: some errors detected:
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
\e[90m# Error @ \e[0;0m\e]8;;$file_url#1:3\e\\\e[90msomefile.jl:1:3\e[0;0m\e]8;;\e\\
a \e[48;2;120;70;70m--\e[0;0m b -- c
\e[90m# └┘ ── \e[0;0m\e[91minvalid operator\e[0;0m"""
Expand All @@ -145,7 +145,7 @@ end
catch exc
@test exc isa JuliaSyntax.ParseError
@test sprint(showerror, exc) == """
ParseError:
ParseError: some errors detected:
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
# Warning @ somefile.jl:1:2
@(a)
#└─┘ ── parenthesizing macro names is unnecessary
Expand All @@ -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
Loading