AdRoll / rebar3_format

Erlang Formatter for Rebar3
https://tech.nextroll.com/blog/dev/2020/02/25/erlang-rebar3-format.html
MIT License
108 stars 21 forks source link

Removing function if it has a syntax error #279

Open rustkas opened 3 years ago

rustkas commented 3 years ago

Describe the bug

When I run rebar3 format for source code that has some syntax error in some function, that function just scapes from source code.

To Reproduce

Make syntax error then run rebar3 format.

Expected behavior

We get a description in a console and damaged source code.

Rebar3 Log

Run rebar3 with DEBUG=1 and paste its output here. (sorry, I can not do that - The code with syntax error is gone)

** 73: unterminated string starting with ",[Result]).\n    " **

Additional context

Bug description for reproducing:

line     Text="abc123, without ending " in the end
line "{ok, MP} = re:compile(Regex)" do not have and "," at the end

Source code:

-module(recipe_14).

-export([]).

%%
%% Tests
%%
-ifdef(TEST).

-include_lib("eunit/include/eunit.hrl").

research_02_01() ->
    %Expected = "12345678910",
    %?debugFmt("~p~n",[Text]),
    Regex = "\\w+\\d+",
    Text="abc123,
    {ok, MP} = re:compile(Regex)
    {match, [Result]} = re:run(Text, MP, [{capture, first, list}]),
    ?debugFmt("~p~n",[Result]).
    %?_assertEqual(Expected, Result).

-endif.

Stacktrace:

H:\books1\regular expression\regex\Regular Expressions Cookbook 2nd\github\code\ch02\basic>rebar3 format
===> Error parsing files: {modified_ast,"lib/recipe_14/src/recipe_14.erl",
                              "lib/recipe_14/src/recipe_14.erl"}
Stack: [{rebar3_ast_formatter,format,3,
                              [{file,"h:/books1/regular expression/regex/Regular Expressions Cookbook 2nd/github/code/ch02/basic/_build/default/plugins/rebar3_format/src/rebar3_ast_formatter.erl"},
                               {line,40}]},
        {rebar3_format_prv,'-format_files/2-fun-0-',2,
                           [{file,"h:/books1/regular expression/regex/Regular Expressions Cookbook 2nd/github/code/ch02/basic/_build/default/plugins/rebar3_format/src/rebar3_format_prv.erl"},
                            {line,125}]},
        {lists,'-filter/2-lc$^0/1-0-',2,[{file,"lists.erl"},{line,1290}]},
        {rebar3_format_prv,format_files,2,
                           [{file,"h:/books1/regular expression/regex/Regular Expressions Cookbook 2nd/github/code/ch02/basic/_build/default/plugins/rebar3_format/src/rebar3_format_prv.erl"},
                            {line,123}]},
        {rebar3_format_prv,do,1,
                           [{file,"h:/books1/regular expression/regex/Regular Expressions Cookbook 2nd/github/code/ch02/basic/_build/default/plugins/rebar3_format/src/rebar3_format_prv.erl"},
                            {line,43}]},
        {rebar_core,do,2,
                    [{file,"/home/runner/work/rebar3/rebar3/src/rebar_core.erl"},
                     {line,155}]},
        {rebar3,run_aux,2,
                [{file,"/home/runner/work/rebar3/rebar3/src/rebar3.erl"},
                 {line,182}]},
        {rebar3,main,1,
                [{file,"/home/runner/work/rebar3/rebar3/src/rebar3.erl"},
                 {line,66}]}]
=ERROR REPORT==== 27-Aug-2021::09:00:37.853000 ===
    modified_ast: lib/recipe_14/src/recipe_14.erl
    removed: [{error,no}]
    added: [{tree,no,
                  {attr,no,[],none},
                  "* * 73 : unterminated string starting with \",[Result]).\\n    \" * *"}]
===> Unknown Formatting Error: {modified_ast,"lib/recipe_14/src/recipe_14.erl",
                              "lib/recipe_14/src/recipe_14.erl"}
elbrujohalcon commented 3 years ago

I found a minimal example to reproduce the bug…

-module(recipe_15).

-export([x/0]).

x() ->
    "This is an unterminated string,
    some:more(stuff).

This results in the following when formatted…

-module(recipe_15).

-export([x/0]).

** 6: unterminated string starting with "This is an unter" **

It's actually an issue with ktn_dodger. When we try to parse the file with no_fail… it fails anyway.

elbrujohalcon commented 3 years ago

I opened inaka/katana-code#66 for this.