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

Error message in plain text discards visual location information #61

Closed
ForceBru opened this issue Aug 22, 2022 · 2 comments
Closed

Error message in plain text discards visual location information #61

ForceBru opened this issue Aug 22, 2022 · 2 comments
Labels
enhancement New feature or request error messages Better, more actionable diagnostics pretty printing

Comments

@ForceBru
Copy link

When I get a syntax error, the offending characters are highlighted:

syntaxError

In fact, they're... "lowlighted", so that the offending character is dimmer than other code (I can barely see the 8 there), but it's still (de)emphasized.

When I copy this error message and paste it as plain text, all formatting is lost, which is expected:

julia> (2+5+8
ERROR: ParseError:
Error: Expected `)` but got unexpected tokens
@ REPL[17]:2:1
(2+5+8

However, nothing visually points at the location of the error anymore: the 8 is no different from other code. Sure, the location is indicated by REPL[17]:2:1 (Does it mean "second line, first character"? Looks more like a "1st line, 6th character" to me...), but the visual is lost. Implementations of other programming languages rely on actual characters (not formatting) to indicate the position of the error.


Python draws a "pointer" to the error location, so a plain-text error message still tells me where the error is:

>>> (2,4,;)
  File "<stdin>", line 1
    (2,4,;)
         ^
SyntaxError: invalid syntax

Clang does this too:

$ cat syntax_error.c 
int main() {
    0
}
$ clang syntax_error.c 
syntax_error.c:2:6: error: expected ';' after expression
    0
     ^
     ;
syntax_error.c:2:5: warning: expression result unused [-Wunused-value]
    0
    ^
1 warning and 1 error generated.

Rust's error messages draw around the offending code all the time, which is extremely helpful.


It would be nice to have error messages one could copy & paste without loss of information, especially visual indication of where the error is.

  • Julia 1.8.0
  • JuliaSyntax.jl 0.1.0
@pfitzseb pfitzseb added the enhancement New feature or request label Aug 22, 2022
@c42f
Copy link
Member

c42f commented Aug 23, 2022

In fact, they're... "lowlighted

This shouldn't happen and seems like a bug in the highlighting code, or more likely a problem that the code currently assumes high quality color in the terminal emulator.

Perhaps you've only got 16 or 256 terminal background colors. Which terminal are you using?

"pointer" to the error location

I'd definitely like a text-only mode as an option. But I think this would be worse in two key ways:

  • It disturbs the visual shape of the code much more than a simple highlighting scheme
  • With unicode we'd have to reliably compute the text width which isn't exactly possible in a terminal. We sidestep this entirely by just using a background color. Other people have come to the same conclusion, for example: http://technomancy.us/198

@c42f
Copy link
Member

c42f commented Mar 13, 2023

Should be fixed or at least greatly improved by #215

@c42f c42f closed this as completed Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request error messages Better, more actionable diagnostics pretty printing
Projects
None yet
Development

No branches or pull requests

3 participants