Julia: Better line info for "missing comma or ) in argument list" error

Created on 2 May 2016  路  11Comments  路  Source: JuliaLang/julia

Putting this in a file and include it:

function filler()
end

function g(a,b,c)
    f(a,b)
    f(a,b)
    f(a,(b,))
    f(a,(b,))
    f(a,(b,))
    f(a,(b,) # :(
    f(a,(b,))
    f(a,(b,))
    f(a,(b,))
end

gives the error message:

julia> include("test.jl")
ERROR: LoadError: syntax: missing comma or ) in argument list
 in include(::ASCIIString) at ./boot.jl:233
 in include_from_node1(::ASCIIString) at ./loading.jl:426
 in eval(::Module, ::Any) at ./boot.jl:236
while loading /home/kristoffer/Documents/test.jl, in expression starting on line 4

Is there anyway the line info could be a bit more specific than just the line of the start of the enclosing function?

error handling parser

Most helpful comment

Or you could just use JuliaParser ;):
screen shot 2016-05-02 at 12 39 25 pm

All 11 comments

That one has the title "bad stack trace for errors in macros". This example has no macros. Should the title in #15643 be updated?

Looks like a different issue to me. This one is about syntax error locations.

Or you could just use JuliaParser ;):
screen shot 2016-05-02 at 12 39 25 pm

Wow, that is some clang level beauty right there.

The README has instructions: https://github.com/JuliaLang/JuliaParser.jl#using-juliaparser-as-your-primary-parser

Here is another example from a typo I made:

# test.jl
module Test

function filler()
    blabla
end

typealias a = Float64

end # module
julia> include("/home/kristoffer/Documents/test.jl")
ERROR: LoadError: syntax: unexpected "="
 in include_from_node1(::String) at ./loading.jl:426
 in eval(::Module, ::Any) at ./boot.jl:230
while loading /home/kristoffer/Documents/test.jl, in expression starting on line 1

Another one:

module M

function f()
    while true
        if x == 0 && y == 0
            a = 1
        if x == 1 && z == 1
            a = 2
        end
    end
end

end

This gives ERROR: syntax: incomplete: "module" at REPL[44]:1 requires end. For a large modules this is a quite unhelpful error and I usually end up pasting the whole module in the REPL and see where the latest completely parsed expression got completed. Maybe the Error message could show this as well?

I think the best way to give better error messages is probably to consider indentation. To me that suggests bailing out on a parse when there's an error and reparsing the input with a parser that is slower and tracks extra information like indentation and gives really high quality messages.

Would be awesome if we could have https://github.com/KristofferC/OhMyREPL.jl replace the default on_done / parse_input_line function with one that uses that fancier parser (https://github.com/ZacLN/CSTParser.jl) hint hint hint :) :) :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dpsanders picture dpsanders  路  3Comments

i-apellaniz picture i-apellaniz  路  3Comments

ararslan picture ararslan  路  3Comments

tkoolen picture tkoolen  路  3Comments

omus picture omus  路  3Comments