Line numbers in escript errors?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Line numbers in escript errors?

Roger Lipscombe-2
When something goes wrong in my escript, I get something like this:

escript: exception error: no match of right hand side value
                 {ok, ...}
  in function  erl_eval:expr/5 (erl_eval.erl, line 453)
  in call from erl_eval:exprs/5 (erl_eval.erl, line 126)
  in call from lists:foldl/3 (lists.erl, line 1263)

...but it doesn't tell me which line in my script was at fault. Is
there a way to get escript to divulge that information?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Line numbers in escript errors?

Danil Zagoskin-2
Hi!

Do you use compile mode?
It gives much more meaningful stacktraces (especially when you specify module name as well):

$ cat hello.escript
#!/usr/bin/env escript
-module(hello).
-mode(compile).

main(_) ->
  [1/X || X <- lists:seq(-5, 2)].


$ ./hello.escript
escript: exception error: an error occurred when evaluating an arithmetic expression
  in function  hello:'-main/1-lc$^0/1-0-'/1 (./hello.escript, line 6)
  in call from hello:'-main/1-lc$^0/1-0-'/1 (./hello.escript, line 6)
  in call from escript:run/2 (escript.erl, line 758)
  in call from escript:start/1 (escript.erl, line 277)
  in call from init:start_em/1
  in call from init:do_boot/3

On Tue, Jul 16, 2019 at 1:38 PM Roger Lipscombe <[hidden email]> wrote:
When something goes wrong in my escript, I get something like this:

escript: exception error: no match of right hand side value
                 {ok, ...}
  in function  erl_eval:expr/5 (erl_eval.erl, line 453)
  in call from erl_eval:exprs/5 (erl_eval.erl, line 126)
  in call from lists:foldl/3 (lists.erl, line 1263)

...but it doesn't tell me which line in my script was at fault. Is
there a way to get escript to divulge that information?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


--
Danil Zagoskin | [hidden email]

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Line numbers in escript errors?

zxq9-2
On 2019年7月16日火曜日 14時01分57秒 JST Danil Zagoskin wrote:

> Hi!
>
> Do you use compile mode?
> -mode(compile).
>
> On Tue, Jul 16, 2019 at 1:38 PM Roger Lipscombe <[hidden email]>
> wrote:
>
> > When something goes wrong in my escript, I get something like this:
> >
> > escript: exception error: no match of right hand side value
> >                  {ok, ...}
> >   in function  erl_eval:expr/5 (erl_eval.erl, line 453)
> >   in call from erl_eval:exprs/5 (erl_eval.erl, line 126)
> >   in call from lists:foldl/3 (lists.erl, line 1263)
> >
> > ...but it doesn't tell me which line in my script was at fault. Is
> > there a way to get escript to divulge that information?

Another useful thing is to make sure your set to unicode mode with
io:setopts/1. This can be perplexing to troubleshoot.

I tend to start experiments with this as a template:


  #! /usr/bin/env escript
 
  -mode(compile).
 
  main(Args) ->
      ok = io:setopts([{encoding, unicode}]),
      io:format("Escript received the args: ~tp~n", [Args]).


-Craig
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions