domluna / JuliaFormatter.jl

An opinionated code formatter for Julia. Plot twist - the opinion is your own.
https://domluna.github.io/JuliaFormatter.jl/dev/
MIT License
579 stars 69 forks source link

Syntax errors should output location #276

Open eschnett opened 4 years ago

eschnett commented 4 years ago

When I try to format a piece of code with a syntax error (e.g. too many closing parentheses), then the formatter outputs the whole source code (very long) along with a stack backtrace, but doesn't point to the actual error. It would be convenient if it pointed to the error, with an error message similar to one that Julia would report.

eschnett commented 4 years ago

Note: The current release outputs line and column number

ERROR: Parsing error for input occured on line 836, offset: 3

but doesn't output the file name yet.

domluna commented 4 years ago

I think if you do verbose=true the filename will appear before the error message, i.e.

formatting file.jl
ERROR: ...

So that could be a way to get around it for now.

For a proper fix the error would have to be caught from format_file since that's where the filename is known and then I guess the error message would have to be altered slightly.

nickrobinson251 commented 4 years ago

verbose=true is really helpful -- it helped me track down the file causing this issue https://github.com/domluna/JuliaFormatter.jl/issues/311

it'd still be nice to be even more precise with where the error was (if possible)

I only new about verbose due to this issue, so i will open a PR to make it more prominent in the docs, if that's okay?

domluna commented 4 years ago

@nickrobinson251 sure