rebar3 icon indicating copy to clipboard operation
rebar3 copied to clipboard

Improved compile messages

Open tsloughter opened this issue 1 year ago • 4 comments

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 avatar Apr 08 '23 11:04 tsloughter

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 https://github.com/erlang/rebar3/pull/2783

ferd avatar Apr 08 '23 23:04 ferd

(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)

ferd avatar Apr 08 '23 23:04 ferd

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.

michalmuskala avatar Apr 19 '23 10:04 michalmuskala

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.

tsloughter avatar Apr 19 '23 11:04 tsloughter