From 4ab05f4a8e6c46c296b896b42a3e09c2559e7c73 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" <142223309+kivra-pauoli@users.noreply.github.com> Date: Sat, 10 Feb 2024 10:39:23 +0000 Subject: [PATCH] Prevent rebar3 crash and more output than required (#61) This was: 1. throwing on rebar3's call to code:which, which assumes a return like {error, {Module, Reason}} 2. returning the values of the analysis as a term while also printing them to stdout --- src/rebar3_lint_prv.erl | 10 +++------- test/test_app_SUITE.erl | 4 +--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/rebar3_lint_prv.erl b/src/rebar3_lint_prv.erl index a140195..568dfed 100644 --- a/src/rebar3_lint_prv.erl +++ b/src/rebar3_lint_prv.erl @@ -1,6 +1,6 @@ -module(rebar3_lint_prv). --export([init/1, do/1, format_error/1]). +-export([init/1, do/1]). -export([default_config/0]). -define(PROVIDER, lint). @@ -31,17 +31,13 @@ do(State) -> {ok, State}; {fail, [{throw, Error} | _]} -> rebar_api:abort("elvis_core threw an exception: ~p", [Error]); - {fail, Reason} -> - {error, {"Linting failed with ~p", Reason}} + {fail, _} -> + {error, "Linting failed"} catch Error -> rebar_api:abort("elvis_core threw an exception: ~p", [Error]) end. --spec format_error({string(), any()}) -> iolist(). -format_error({Message, Reason}) -> - io_lib:format(Message, [Reason]). - -spec get_elvis_config(rebar_state:t()) -> elvis_config:configs(). get_elvis_config(State) -> try_elvis_config_rebar(State). diff --git a/test/test_app_SUITE.erl b/test/test_app_SUITE.erl index 4479f53..d55e235 100644 --- a/test/test_app_SUITE.erl +++ b/test/test_app_SUITE.erl @@ -19,6 +19,4 @@ test_app(_Config) -> [#{dirs => ["src"], filter => "*.erl", rules => [{elvis_style, max_function_length, #{max_length => 1}}]}]), - {error, {Message = "Linting failed with ~p", Reason}} = rebar3_lint_prv:do(BadState), - % Check that this doesn't throw - io:format("~p", [rebar3_lint_prv:format_error({Message, Reason})]). + {error, "Linting failed"} = rebar3_lint_prv:do(BadState).