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

Improved compile messages #2782

Open
tsloughter opened this issue Apr 8, 2023 · 4 comments
Open

Improved compile messages #2782

tsloughter opened this issue Apr 8, 2023 · 4 comments
Labels
enhancement new behaviour or additional functionality help wanted unlikely to be tackled by core maintainers

Comments

@tsloughter
Copy link
Collaborator

I hadn't thought about the fact that we have all the info (column numbers) these days to output those fancy error messages like you see in Elm or Rust until I saw it with eqwalizer when running it on code which didn't compile:

error: parse_error
    ┌─ apps/opentelemetry/src/otel_tracer_server.erl:105:3
    │
105 │   when Tracer =/= undefined ->
    │   ^^^^ syntax error before: 'when'

vs

===> Compiling apps/opentelemetry/src/otel_tracer_server.erl failed
apps/opentelemetry/src/otel_tracer_server.erl:105:3: syntax error before: 'when'

It isn't that useful but opening this to track it and say hey, 'if someone sees this and wants to implement it that'd be nice' :)

@tsloughter tsloughter added enhancement new behaviour or additional functionality help wanted unlikely to be tackled by core maintainers labels Apr 8, 2023
@ferd
Copy link
Collaborator

ferd commented Apr 8, 2023

This isn't really hard and I wanted to give it a try for a partial implementation to see the style, it looks like this so far:

-module(rebar_fake).

-export([diagnostic/1]).

diagnostic(A) ->
    X = add(5 / 0),
    {X,X}.

add(X) -> X.

add(X, Y) -> X + Y.

Calling rebar3 escriptize:

...
===> Compiling rebar
===> Compiling apps/rebar/src/rebar_fake.erl failed
apps/rebar/src/rebar_fake.erl:5:12:
  diagnostic(A) ->
             ^-- variable 'A' is unused
apps/rebar/src/rebar_fake.erl:6:15:
      X = add(5 / 0),
                ^-- evaluation of operator '/'/2 will fail with a 'badarith' exception
apps/rebar/src/rebar_fake.erl:11:1:
  add(X, Y) -> X + Y.
  ^-- function add/2 is unused

Seems to be okay-ish.

See #2783

@ferd
Copy link
Collaborator

ferd commented Apr 8, 2023

(this draft PR is likely to look like garbage on errors on long long lines I guess, but it shows a very easy way to get improvements)

@michalmuskala
Copy link

michalmuskala commented Apr 19, 2023

What we have in eqwalizer is actually not available in regular Erlang. We not only have line + column, but we actually have full start/end range for every construct in AST (the price is that the AST format is not backwards compatible). This allows the reported ranges to be precise, rather than just the single point information that Erlang compiler has - that said, this is still better than just line information.

@tsloughter
Copy link
Collaborator Author

Ah, I thought it did the range based on the error itself. Like if the error says there is an issue at when then you know to highlight the whole when.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new behaviour or additional functionality help wanted unlikely to be tackled by core maintainers
Projects
None yet
Development

No branches or pull requests

3 participants