Просмотр исходного кода

fix: friendly error message when creating bridges with too long names

This commit makes the error message and log entry that appear when one
tries to create a bridge with a name the exceeds 255 bytes (the max
length for atoms) more friendly and easier to understand.

An even better fix would be to not store bridge names as atoms but this
probably requires a more substantial change.

Fixes:
https://emqx.atlassian.net/browse/EMQX-9609
Kjell Winblad 2 лет назад
Родитель
Сommit
75ff76a16b

+ 11 - 0
apps/emqx/src/emqx_config_handler.erl

@@ -473,6 +473,17 @@ bin_path(ConfKeyPath) -> [bin(Key) || Key <- ConfKeyPath].
 bin(A) when is_atom(A) -> atom_to_binary(A, utf8);
 bin(A) when is_atom(A) -> atom_to_binary(A, utf8);
 bin(B) when is_binary(B) -> B.
 bin(B) when is_binary(B) -> B.
 
 
+atom(Bin) when is_binary(Bin), size(Bin) > 255 ->
+    erlang:throw(
+        iolist_to_binary(
+            io_lib:format(
+                "Name is is too long."
+                " Please provide a shorter name (<= 255 bytes)."
+                " The name that is too long: \"~s\"",
+                [Bin]
+            )
+        )
+    );
 atom(Bin) when is_binary(Bin) ->
 atom(Bin) when is_binary(Bin) ->
     binary_to_atom(Bin, utf8);
     binary_to_atom(Bin, utf8);
 atom(Str) when is_list(Str) ->
 atom(Str) when is_list(Str) ->

+ 1 - 1
apps/emqx_bridge/src/emqx_bridge_api.erl

@@ -605,7 +605,7 @@ create_or_update_bridge(BridgeType, BridgeName, Conf, HttpStatusCode) ->
     case emqx_bridge:create(BridgeType, BridgeName, Conf) of
     case emqx_bridge:create(BridgeType, BridgeName, Conf) of
         {ok, _} ->
         {ok, _} ->
             lookup_from_all_nodes(BridgeType, BridgeName, HttpStatusCode);
             lookup_from_all_nodes(BridgeType, BridgeName, HttpStatusCode);
-        {error, #{kind := validation_error} = Reason} ->
+        {error, Reason} when is_map(Reason) ->
             ?BAD_REQUEST(map_to_json(Reason))
             ?BAD_REQUEST(map_to_json(Reason))
     end.
     end.
 
 

+ 1 - 1
apps/emqx_rule_engine/src/emqx_rule_engine.app.src

@@ -2,7 +2,7 @@
 {application, emqx_rule_engine, [
 {application, emqx_rule_engine, [
     {description, "EMQX Rule Engine"},
     {description, "EMQX Rule Engine"},
     % strict semver, bump manually!
     % strict semver, bump manually!
-    {vsn, "5.0.18"},
+    {vsn, "5.0.19"},
     {modules, []},
     {modules, []},
     {registered, [emqx_rule_engine_sup, emqx_rule_engine]},
     {registered, [emqx_rule_engine_sup, emqx_rule_engine]},
     {applications, [kernel, stdlib, rulesql, getopt, emqx_ctl]},
     {applications, [kernel, stdlib, rulesql, getopt, emqx_ctl]},

+ 1 - 1
lib-ee/emqx_ee_bridge/src/emqx_ee_bridge.app.src

@@ -1,6 +1,6 @@
 {application, emqx_ee_bridge, [
 {application, emqx_ee_bridge, [
     {description, "EMQX Enterprise data bridges"},
     {description, "EMQX Enterprise data bridges"},
-    {vsn, "0.1.14"},
+    {vsn, "0.1.15"},
     {registered, []},
     {registered, []},
     {applications, [
     {applications, [
         kernel,
         kernel,