Skip to content

Commit 1d8db94

Browse files
committed
Ensure provider hook calls don't crash because of invalid command line arguments
Normally the CLI arguments are intended for the provider which is called directly. When these are forwarded to other providers through hooks things might break.
1 parent 1604e4f commit 1d8db94

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/rebar_hooks.erl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ run_all_hooks(Dir, Type, Command, Providers, State) ->
2222
run_hooks(Dir, Type, Command, rebar_state:opts(State), State).
2323

2424
run_project_and_app_hooks(Dir, Type, Command, Providers, State) ->
25-
ProjectApps = rebar_state:project_apps(State),
26-
[rebar_hooks:run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) || AppInfo <- ProjectApps],
27-
run_all_hooks(Dir, Type, Command, Providers, State).
25+
% The command_args which the original invocation of rebar received are most
26+
% likely not applicable to the hooks which will be called. Therefore, the
27+
% args are discarded to not crash provider hook invocations.
28+
State1 = rebar_state:command_args(State, []),
29+
ProjectApps = rebar_state:project_apps(State1),
30+
[rebar_hooks:run_all_hooks(Dir, Type, Command, Providers, AppInfo, State1) || AppInfo <- ProjectApps],
31+
run_all_hooks(Dir, Type, Command, Providers, State1).
2832

2933
run_provider_hooks(Dir, Type, Command, Providers, Opts, State) ->
3034
case rebar_opts:get(Opts, provider_hooks, []) of

0 commit comments

Comments
 (0)