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