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
This commit is contained in:
Kjell Winblad 2023-06-01 15:30:06 +02:00
parent 6b5b9fc8b8
commit 75ff76a16b
4 changed files with 14 additions and 3 deletions

View File

@ -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) ->

View File

@ -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.

View File

@ -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]},

View File

@ -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,