Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --eval option to shell #2728

Merged
merged 2 commits into from
Jul 18, 2022
Merged

Add --eval option to shell #2728

merged 2 commits into from
Jul 18, 2022

Conversation

choptastic
Copy link
Contributor

Hey folks,

I'm not sure if there's an equivalent function in rebar3 or not, but I found a need to sort-of re-implement erl -eval but for the rebar3 shell command, so rebar3 shell --eval "my_module:my_function()".

This implementation also works like erl -eval in that it supports multiple --eval arguments.

Thoughts?

@ferd
Copy link
Collaborator

ferd commented Jul 12, 2022

Looks workable. What's the expected behaviour when someone submits gibberish? Is it different or inline with what -eval does in the shell?

@choptastic
Copy link
Contributor Author

Hey @ferd, good question. At this point, my expected behavior was "crash with whatever error message it happens to produce."

Which, right now, looks like this:

==> Evaluating: "sdfg()"
===> Uncaught error in rebar_core. Run with DIAGNOSTIC=1 to see stacktrace or consult rebar3.crashdump
===> When submitting a bug report, please include the output of `rebar3 report "your command"`

with DIAGNOSTIC=1 on, it looks like this:

===> Found shell evals from command line option.
===> Evaluating: "sdfg()"
===> Uncaught error in rebar_core. Run with DIAGNOSTIC=1 to see stacktrace or consult rebar3.crashdump
===> Uncaught error: {badmatch,
                                {error,
                                    {1,erl_parse,
                                     ["syntax error before: ",[]]}}}
===> Stack trace to the error location:
[{rebar_prv_shell,eval,1,
                  [{file,"/home/gumm/code/rebar3/src/rebar_prv_shell.erl"},
                   {line,357}]},
 {lists,map,2,[{file,"lists.erl"},{line,1315}]},
 {rebar_prv_shell,shell,1,
                  [{file,"/home/gumm/code/rebar3/src/rebar_prv_shell.erl"},
                   {line,135}]},
 {rebar_core,do,2,
             [{file,"/home/gumm/code/rebar3/src/rebar_core.erl"},{line,155}]},
 {rebar3,run_aux,2,
         [{file,"/home/gumm/code/rebar3/src/rebar3.erl"},{line,193}]},
 {rebar3,main,1,[{file,"/home/gumm/code/rebar3/src/rebar3.erl"},{line,66}]},
 {escript,run,2,[{file,"escript.erl"},{line,750}]},
 {escript,start,1,[{file,"escript.erl"},{line,277}]}]

Which could be made more straigthtforward.

If you'd like, I can make these changes sometime in about 2 weeks (traveling for the next few weeks, so won't be doing much by way of this kind of stuff).

Whadya think?

@ferd
Copy link
Collaborator

ferd commented Jul 15, 2022

Cleaner error descriptions there would be worth it just to reduce error reports and point towards the issue being in the script being evaluated. It's fine to wait on my end. I'm on vacation as well and doing little OSS.

@choptastic
Copy link
Contributor Author

Rock on!

@choptastic
Copy link
Contributor Author

I've updated it to give some better error messages so the user clearly knows it's the --eval switch that's crashing and why it's crashing:

bad syntax error:

$ ./rebar3 shell --eval "io:f)."
...
Eshell V13.0.1  (abort with ^G)
1> ===> Evaluating: "io:f)."
===> Failed to parse -eval expression: "io:f).". Error message: syntax error before: ')'

Valid syntax but the call fails for some reason

./rebar3 shell --eval "no_function()."
...
Eshell V13.0.1  (abort with ^G)
1> ===> Evaluating: "no_function()."
===l> Failed to evaluate expression: "no_function().". Error: error:undef. Run with DIAGNOSTIC=1 to stacktrace or consult rebar3.crashdump

The above, but with DIAGNOSTIC=1:

Eshell V13.0.1  (abort with ^G)
1> ===> No script_file specified.
===> Found shell evals from command line option.
===> Evaluating: "no_function()."
===> --eval failure details: error:undef
Stacktrace: [{erl_eval,no_function,0,[]},
             {erl_eval,local_func,8,[{file,"erl_eval.erl"},{line,660}]},
             {rebar_prv_shell,eval,1,
                              [{file,"/home/gumm/code/rebar3/src/rebar_prv_shell.erl"},
                               {line,366}]},
             {lists,map,2,[{file,"lists.erl"},{line,1315}]},
             {rebar_prv_shell,shell,1,
                              [{file,"/home/gumm/code/rebar3/src/rebar_prv_shell.erl"},
                               {line,140}]},
             {rebar_core,do,2,
                         [{file,"/home/gumm/code/rebar3/src/rebar_core.erl"},
                          {line,155}]},
             {rebar3,run_aux,2,
                     [{file,"/home/gumm/code/rebar3/src/rebar3.erl"},
                      {line,193}]},
             {rebar3,main,1,
                     [{file,"/home/gumm/code/rebar3/src/rebar3.erl"},
                      {line,66}]}]
===> Failed to evaluate expression: "no_function().". Error: error:undef. Run with DIAGNOSTIC=1 to stacktrace or consult rebar3.crashdump

No rush on this - enjoy your vacation!

@ferd ferd merged commit 017c7fc into erlang:main Jul 18, 2022
@choptastic
Copy link
Contributor Author

Thanks for merging!

@choptastic choptastic deleted the shell-eval branch July 20, 2022 20:13
choptastic added a commit to choptastic/rebar3.org that referenced this pull request Aug 24, 2022
choptastic added a commit to choptastic/rebar3.org that referenced this pull request Aug 29, 2022
choptastic added a commit to choptastic/rebar3.org that referenced this pull request Aug 29, 2022
choptastic added a commit to choptastic/rebar3.org that referenced this pull request Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants