[erlang-questions] Run-time error messages

Richard A. O'Keefe ok@REDACTED
Mon Oct 3 02:49:18 CEST 2016


A student just asked me for help finding a bug in his
Erlang code.  This was the line responsible:

ChosenTopic = lists:nth(
   rand:uniform(length(AvailableTopics-1)), AvailableTopics),
                       ^^^^^^^^^^^^^^^^^
Of course the Dialyzer would spot this in a flash
(AvailableTopics is a list), but the dialyzer hadn't been
installed on the lab machines.

The error message was
     {badarith,[{client,choose_topics,3,[{file,"client.erl"},{line,145}]},
                {client,start,0,[{file,"client.erl"},{line,8}]}]}

where {line,145} points to the beginning of the function
where the error is, not even to the beginning of the clause.
If the error message had shown even just which operation was
involved ('-'), the student would have found the problem by
himself.  As it was, he was looking all over (especially at
line 145).

Since we're nearly at the end of the semester,
my action items are
  - get the latest Erlang release installed by the start
    of next semester
  - ensure that the dialyzer is installed and the PLT built
    as part of this
  - teach Erlang type specifications and how to use the
    dialyzer next time I teach anything about Erlang.

Even so, it would be nice if 'badarith' were less vague.






More information about the erlang-questions mailing list