fix(rule_engine): compile warnings on the macro RAISE
This commit is contained in:
parent
fbf8d3e111
commit
d86b5ef210
|
@ -140,31 +140,17 @@
|
|||
-define(is_logical(Op), (Op =:= 'and' orelse Op =:= 'or')).
|
||||
|
||||
-define(RAISE(_EXP_, _ERROR_),
|
||||
fun() ->
|
||||
try (_EXP_)
|
||||
catch _EXCLASS_:_REASON_:_ST_ ->
|
||||
throw(_ERROR_)
|
||||
end
|
||||
end()).
|
||||
?RAISE(_EXP_, _ = do_nothing, _ERROR_)).
|
||||
|
||||
-define(RAISE(_EXP_, _EXP_ON_FAIL_, _ERROR_),
|
||||
fun() ->
|
||||
try (_EXP_)
|
||||
catch _EXCLASS_:_EXCPTION_:_ST_ ->
|
||||
_REASON_ = {_EXCLASS_, _EXCPTION_},
|
||||
_EXP_ON_FAIL_,
|
||||
throw(_ERROR_)
|
||||
end
|
||||
end()).
|
||||
|
||||
-define(THROW(_EXP_, _ERROR_),
|
||||
begin
|
||||
try (_EXP_)
|
||||
catch _:_ ->
|
||||
throw(_ERROR_)
|
||||
end
|
||||
end).
|
||||
|
||||
%% Tables
|
||||
-define(RULE_TAB, emqx_rule).
|
||||
-define(ACTION_TAB, emqx_rule_action).
|
||||
|
|
|
@ -489,7 +489,7 @@ init_resource(Module, OnCreate, ResId, Config) ->
|
|||
Params = ?RAISE(Module:OnCreate(ResId, Config),
|
||||
start_reinitial_loop(ResId),
|
||||
{{init_resource_failure, node()},
|
||||
{{Module, OnCreate}, {_REASON_, _ST_}}}),
|
||||
{{Module, OnCreate}, {_EXCLASS_,_EXCPTION_, _ST_}}}),
|
||||
ResParams = #resource_params{id = ResId,
|
||||
params = Params,
|
||||
status = #{is_alive => true}},
|
||||
|
@ -497,7 +497,7 @@ init_resource(Module, OnCreate, ResId, Config) ->
|
|||
|
||||
init_action(Module, OnCreate, ActionInstId, Params) ->
|
||||
ok = emqx_rule_metrics:create_metrics(ActionInstId),
|
||||
case ?RAISE(Module:OnCreate(ActionInstId, Params), {{init_action_failure, node()}, {{Module,OnCreate},{_REASON_,_ST_}}}) of
|
||||
case ?RAISE(Module:OnCreate(ActionInstId, Params), {{init_action_failure, node()}, {{Module,OnCreate},{_EXCLASS_,_EXCPTION_,_ST_}}}) of
|
||||
{Apply, NewParams} when is_function(Apply) -> %% BACKW: =< e4.2.2
|
||||
ok = emqx_rule_registry:add_action_instance_params(
|
||||
#action_instance_params{id = ActionInstId, params = NewParams, apply = Apply});
|
||||
|
@ -517,7 +517,7 @@ clear_resource(Module, Destroy, ResId) ->
|
|||
case emqx_rule_registry:find_resource_params(ResId) of
|
||||
{ok, #resource_params{params = Params}} ->
|
||||
?RAISE(Module:Destroy(ResId, Params),
|
||||
{{destroy_resource_failure, node()}, {{Module, Destroy}, {_REASON_,_ST_}}}),
|
||||
{{destroy_resource_failure, node()}, {{Module, Destroy}, {_EXCLASS_,_EXCPTION_,_ST_}}}),
|
||||
ok = emqx_rule_registry:remove_resource_params(ResId);
|
||||
not_found ->
|
||||
ok
|
||||
|
@ -546,7 +546,7 @@ clear_action(Module, Destroy, ActionInstId) ->
|
|||
case emqx_rule_registry:get_action_instance_params(ActionInstId) of
|
||||
{ok, #action_instance_params{params = Params}} ->
|
||||
?RAISE(Module:Destroy(ActionInstId, Params),{{destroy_action_failure, node()},
|
||||
{{Module, Destroy}, {_REASON_,_ST_}}}),
|
||||
{{Module, Destroy}, {_EXCLASS_,_EXCPTION_,_ST_}}}),
|
||||
ok = emqx_rule_registry:remove_action_instance_params(ActionInstId);
|
||||
not_found ->
|
||||
ok
|
||||
|
|
|
@ -325,7 +325,7 @@ with_opts(Action, RawParams, OptSpecList, {CmdObject, CmdName}) ->
|
|||
|
||||
parse_actions(Actions) ->
|
||||
?RAISE([parse_action(Action) || Action <- Actions],
|
||||
{invalid_action_params, {_REASON_,_ST_}}).
|
||||
{invalid_action_params, {_EXCLASS_,_EXCPTION_,_ST_}}).
|
||||
|
||||
parse_action(Action) ->
|
||||
ActName = maps:get(<<"name">>, Action),
|
||||
|
|
|
@ -87,10 +87,10 @@ do_apply_rule(#rule{id = RuleId,
|
|||
on_action_failed = OnFailed,
|
||||
actions = Actions}, Input) ->
|
||||
{Selected, Collection} = ?RAISE(select_and_collect(Fields, Input),
|
||||
{select_and_collect_error, {_REASON_,_ST_}}),
|
||||
{select_and_collect_error, {_EXCLASS_,_EXCPTION_,_ST_}}),
|
||||
ColumnsAndSelected = maps:merge(Input, Selected),
|
||||
case ?RAISE(match_conditions(Conditions, ColumnsAndSelected),
|
||||
{match_conditions_error, {_REASON_,_ST_}}) of
|
||||
{match_conditions_error, {_EXCLASS_,_EXCPTION_,_ST_}}) of
|
||||
true ->
|
||||
ok = emqx_rule_metrics:inc(RuleId, 'rules.matched'),
|
||||
Collection2 = filter_collection(Input, InCase, DoEach, Collection),
|
||||
|
@ -106,9 +106,9 @@ do_apply_rule(#rule{id = RuleId,
|
|||
on_action_failed = OnFailed,
|
||||
actions = Actions}, Input) ->
|
||||
Selected = ?RAISE(select_and_transform(Fields, Input),
|
||||
{select_and_transform_error, {_REASON_,_ST_}}),
|
||||
{select_and_transform_error, {_EXCLASS_,_EXCPTION_,_ST_}}),
|
||||
case ?RAISE(match_conditions(Conditions, maps:merge(Input, Selected)),
|
||||
{match_conditions_error, {_REASON_,_ST_}}) of
|
||||
{match_conditions_error, {_EXCLASS_,_EXCPTION_,_ST_}}) of
|
||||
true ->
|
||||
ok = emqx_rule_metrics:inc(RuleId, 'rules.matched'),
|
||||
{ok, take_actions(Actions, Selected, Input, OnFailed)};
|
||||
|
@ -170,11 +170,11 @@ filter_collection(Input, InCase, DoEach, {CollKey, CollVal}) ->
|
|||
fun(Item) ->
|
||||
InputAndItem = maps:merge(Input, #{CollKey => Item}),
|
||||
case ?RAISE(match_conditions(InCase, InputAndItem),
|
||||
{match_incase_error, {_REASON_,_ST_}}) of
|
||||
{match_incase_error, {_EXCLASS_,_EXCPTION_,_ST_}}) of
|
||||
true when DoEach == [] -> {true, InputAndItem};
|
||||
true ->
|
||||
{true, ?RAISE(select_and_transform(DoEach, InputAndItem),
|
||||
{doeach_error, {_REASON_,_ST_}})};
|
||||
{doeach_error, {_EXCLASS_,_EXCPTION_,_ST_}})};
|
||||
false -> false
|
||||
end
|
||||
end, CollVal).
|
||||
|
|
|
@ -1908,7 +1908,7 @@ t_sqlparse_array_range_1(_Config) ->
|
|||
Sql02 = "select "
|
||||
" payload.a[1..4] as c "
|
||||
"from \"t/#\" ",
|
||||
?assertThrow({select_and_transform_error,{{range_get,non_list_data},_}},
|
||||
?assertThrow({select_and_transform_error, {error,{range_get,non_list_data},_}},
|
||||
emqx_rule_sqltester:test(
|
||||
#{<<"rawsql">> => Sql02,
|
||||
<<"ctx">> =>
|
||||
|
|
Loading…
Reference in New Issue