Skip to content

Commit b040918

Browse files
Output more context on error (#60)
* Fix our spec.s as per elvis_core and output more context on error The test is a dumb one, not unlike the prior version of it, but it makes sure we don't crash on function call (mimics rebar3) and on io:format'ing it * Bump elvis_core from 3.2.0 to 3.2.1
1 parent bd5fbd4 commit b040918

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
%% == Dependencies and plugins ==
1414

15-
{deps, [{elvis_core, "3.2.0"}]}.
15+
{deps, [{elvis_core, "3.2.1"}]}.
1616

1717
{project_plugins,
1818
[{rebar3_hank, "~> 1.4.0"},

rebar.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{"1.2.0",
2-
[{<<"elvis_core">>,{pkg,<<"elvis_core">>,<<"3.2.0">>},0},
2+
[{<<"elvis_core">>,{pkg,<<"elvis_core">>,<<"3.2.1">>},0},
33
{<<"katana_code">>,{pkg,<<"katana_code">>,<<"2.1.0">>},1},
44
{<<"zipper">>,{pkg,<<"zipper">>,<<"1.0.1">>},1}]}.
55
[
66
{pkg_hash,[
7-
{<<"elvis_core">>, <<"1B8DD3190903ED7520D03DD53E7535574CFC7354C89FA580BE8FD3F65A70C248">>},
7+
{<<"elvis_core">>, <<"D5EFDBC55D14521BAB9337FA6822EB41085377BDB1059B2E6794333F40AE4DC1">>},
88
{<<"katana_code">>, <<"0C42BDCD7E59995876AED9F678CF62E3D12EF42E0FBB2190556E64BFEBDD15C6">>},
99
{<<"zipper">>, <<"3CCB4F14B97C06B2749B93D8B6C204A1ECB6FAFC6050CACC3B93B9870C05952A">>}]},
1010
{pkg_hash_ext,[
11-
{<<"elvis_core">>, <<"05EBF8D4840F4A81721907E1DDCE2F3455BE8EA0F0FB280D50C8DE85C40060FA">>},
11+
{<<"elvis_core">>, <<"4F1996776BB53EF35D0CDA0A6799FC14CDB9190BA89F07883AFCA734D464AE3C">>},
1212
{<<"katana_code">>, <<"AE3BBACA187511588F69695A9FF22251CB2CC672FDCCC180289779BDD25175EF">>},
1313
{<<"zipper">>, <<"6A1FD3E1F0CC1D1DF5642C9A0CE2178036411B0A5C9642851D1DA276BD737C2D">>}]}
1414
].

src/rebar3_lint_prv.erl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,25 @@ init(State) ->
2222
{desc, "A rebar linter plugin based on elvis"}]),
2323
{ok, rebar_state:add_provider(State, Provider)}.
2424

25-
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
25+
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, {string(), any()}}.
2626
do(State) ->
2727
Elvis = get_elvis_config(State),
2828
_ = rebar_log:log(info, "elvis analysis starting, this may take a while...", []),
2929
try elvis_core:rock(Elvis) of
3030
ok ->
3131
{ok, State};
32-
{fail, _} ->
33-
{error, "Linting failed"}
32+
{fail, [{throw, Error} | _]} ->
33+
rebar_api:abort("elvis_core threw an exception: ~p", [Error]);
34+
{fail, Reason} ->
35+
{error, {"Linting failed with ~p", Reason}}
3436
catch
3537
Error ->
3638
rebar_api:abort("elvis_core threw an exception: ~p", [Error])
3739
end.
3840

39-
-spec format_error(any()) -> iolist().
40-
format_error(Reason) ->
41-
io_lib:format("~p", [Reason]).
41+
-spec format_error({string(), any()}) -> iolist().
42+
format_error({Message, Reason}) ->
43+
io_lib:format(Message, [Reason]).
4244

4345
-spec get_elvis_config(rebar_state:t()) -> elvis_config:configs().
4446
get_elvis_config(State) ->

test/test_app_SUITE.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ test_app(_Config) ->
1919
[#{dirs => ["src"],
2020
filter => "*.erl",
2121
rules => [{elvis_style, max_function_length, #{max_length => 1}}]}]),
22-
{error, "Linting failed"} = rebar3_lint_prv:do(BadState).
22+
{error, {Message = "Linting failed with ~p", Reason}} = rebar3_lint_prv:do(BadState),
23+
% Check that this doesn't throw
24+
io:format("~p", [rebar3_lint_prv:format_error({Message, Reason})]).

0 commit comments

Comments
 (0)