From a4f855108c4540db7bea92a9c6c6ae7a80b7d53a Mon Sep 17 00:00:00 2001 From: Kjell Winblad Date: Tue, 18 Jun 2024 15:17:25 +0200 Subject: [PATCH] fix: do not crash when showing rule unsing the cmd interface Before the change the command line command $ bin/emqx ctl rules show rule_0hyd would crash if the rule had bridge actions. This has now been fixed by adding a handler for printing bridge actions. Fixes: https://emqx.atlassian.net/browse/EMQX-12548 --- .../src/emqx_rule_engine_cli.erl | 6 +++++ .../test/emqx_rule_engine_SUITE.erl | 26 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/emqx_rule_engine/src/emqx_rule_engine_cli.erl b/apps/emqx_rule_engine/src/emqx_rule_engine_cli.erl index cda4dc219..7e235b4ee 100644 --- a/apps/emqx_rule_engine/src/emqx_rule_engine_cli.erl +++ b/apps/emqx_rule_engine/src/emqx_rule_engine_cli.erl @@ -95,6 +95,12 @@ format_action(BridgeChannelId) when is_binary(BridgeChannelId) -> io_lib:format("- Name: ~s\n" " Type: data-bridge\n" ,[BridgeChannelId] + ); +format_action({bridge_v2, ActionType, ActionName}) -> + io_lib:format("- Name: ~p\n" + " Action Type: ~p\n" + " Type: data-bridge\n" + ,[ActionName, ActionType] ). left_pad(Str) -> diff --git a/apps/emqx_rule_engine/test/emqx_rule_engine_SUITE.erl b/apps/emqx_rule_engine/test/emqx_rule_engine_SUITE.erl index 395883e7b..680aac759 100644 --- a/apps/emqx_rule_engine/test/emqx_rule_engine_SUITE.erl +++ b/apps/emqx_rule_engine/test/emqx_rule_engine_SUITE.erl @@ -44,7 +44,8 @@ all() -> {group, metrics_simple}, {group, metrics_fail}, {group, metrics_fail_simple}, - {group, tracing} + {group, tracing}, + {group, command_line} ]. suite() -> @@ -147,6 +148,9 @@ groups() -> ]}, {tracing, [], [ t_trace_rule_id + ]}, + {command_line, [], [ + t_command_line_list_print_rule ]} ]. @@ -596,6 +600,26 @@ t_get_rule_ids_by_action(_) -> ?assertEqual([], emqx_rule_engine:get_rule_ids_by_action(<<"mysql:not_exists">>)), ok = delete_rules_by_ids([<<"t_get_rule_ids_by_action">>]). +%% Check that command line interface don't crash when listing and showing rules +t_command_line_list_print_rule(_) -> + ID = <<"t_command_line">>, + Rule1 = #{ + id => ID, + sql => <<"SELECT * FROM \"t\"">>, + actions => [ + #{function => console, args => #{}}, + #{function => republish, args => #{}}, + <<"mqtt:my_mqtt_bridge">>, + <<"mysql:foo">> + ], + description => ID, + created_at => erlang:system_time(millisecond) + }, + ok = create_rules([Rule1]), + ok = emqx_rule_engine_cli:cmd(["list"]), + ok = emqx_rule_engine_cli:cmd(["show", binary_to_list(ID)]), + ok = delete_rules_by_ids([ID]). + t_ensure_action_removed(_) -> Id = <<"t_ensure_action_removed">>, GetSelectedData = <<"emqx_rule_sqltester:get_selected_data">>,