[erlang-questions] Better error messages would be helpful

Richard A. O'Keefe ok@REDACTED
Thu May 16 05:04:23 CEST 2013

I'm in the middle of writing to someone who asked for help with
some Erlang code.  With identifiers replaced, he had

21: f(A, B, C) ->
22:     D = lists:map(fun (E) ->
23:         case proplist:get_value(E, B, error) of
24:         {F} -> {E,F};
25:         error -> {error}
26:         end, A).

erlc reported

./foobar.erl:26: syntax error before: ')'
./foobar.erl:16: function f/3 undefined

When there are error messages that prevent any function from being processed,
it would be helpful if erlc did *NOT* complain about undefined, because that
message is untrue.  The function *was* defined, the compiler just gave up on

But the message that really had him confused was the "syntax error before ')'"
one.  This is the kind of error message one typically gets from something
using Yacc-style parsing.

I didn't like his layout, so I fed his file to an Erlang pretty-printer I
wrote a couple of years.  The code is fast but rather horrible C, so I do
not care to share it.  It was thrown together as an experiment, with an
eye to using it in a text editor.  What did that pile of hacks say?

	Line 26: 'fun' at line 22 closed by ')' (expected 'end'). 

So a better error message is certainly possible.

This is a pretty-printer, not a parser.  Almost the only syntax checking it
does is to keep track of brackets.  But bracket errors are common enough
that it's worth while.

I don't like the idea of slowing erlc down, but I wonder if decent bracket
matching checks could be folded in with macro expansion without too much

More information about the erlang-questions mailing list