[erlang-questions] rebar -- how do I get useful error messages

Tim Watson <>
Sat Dec 3 16:31:56 CET 2011


On 2 December 2011 22:36, Jon Watte <> wrote:

> unfortunately, when I do this, the paths that come out of the compiler
> error messages does not contain the "apps" directory or the name of the
> actual app. For example, if I have an error in the file
> "apps/myapp/src/somefile.erl" then the error message will say
> "src/somefile.erl:44: some error here."
> THIS, in turn, breaks the go-to-compile-error logic for the editor -- it
> cannot find the file in question. I can string-substitute the output of
> rebar to tack on "apps/" in front, but without the actual application,
> that's not good enough, and I don't easily know which app name to also tack
> on.
>
> So -- how do you guys solve this? Jumping to compile errors in the editor
> is one of those basics that nobody really wants to live without, so I can't
> imagine that an entire community is living without...
>
>
I think rebar is not the source of the shortened error message here,
but rather the error message is being generated by the `compile' module
itself. The rebar_erlc_compiler does pass on the 'report' option to
compile:file/2, but this just prints out warnings and errors. The reason
that the error message only contains the 'src' directory is that rebar
changes into subdirectories (using file:set_cwd/1) before processing them.
If you wanted to annotate the errors, you'd need to patch
rebar_erlc_compiler and do something like:

case compile:file(Source, [return_errors|Opts]) of
    {ok, _} -> ok;
    {error, Errors, _} ->
        [ ?ERROR("~s: ~s", [filename:absname(File),
                compile:format_error(Err)]) || {F, Err} <- Errors ],
        ?ABORT("Compilation failed!~n", [])
end;

The place you'd need to make that change is here:
https://github.com/basho/rebar/blob/master/src/rebar_erlc_compiler.erl#L258

HTH. BTW I have no idea whether or not this would make it into rebar, nor
if it's even the best approach. There may be far better ways of doing this,
so I'd suggest discussion on the rebar mailing list as a next step, unless
you're happy maintaining your own fork.

Cheers,

Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111203/dfe3be48/attachment.html>


More information about the erlang-questions mailing list