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:
parent
6b5b9fc8b8
commit
75ff76a16b
|
@ -473,6 +473,17 @@ bin_path(ConfKeyPath) -> [bin(Key) || Key <- ConfKeyPath].
|
|||
bin(A) when is_atom(A) -> atom_to_binary(A, utf8);
|
||||
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) ->
|
||||
binary_to_atom(Bin, utf8);
|
||||
atom(Str) when is_list(Str) ->
|
||||
|
|
|
@ -605,7 +605,7 @@ create_or_update_bridge(BridgeType, BridgeName, Conf, HttpStatusCode) ->
|
|||
case emqx_bridge:create(BridgeType, BridgeName, Conf) of
|
||||
{ok, _} ->
|
||||
lookup_from_all_nodes(BridgeType, BridgeName, HttpStatusCode);
|
||||
{error, #{kind := validation_error} = Reason} ->
|
||||
{error, Reason} when is_map(Reason) ->
|
||||
?BAD_REQUEST(map_to_json(Reason))
|
||||
end.
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{application, emqx_rule_engine, [
|
||||
{description, "EMQX Rule Engine"},
|
||||
% strict semver, bump manually!
|
||||
{vsn, "5.0.18"},
|
||||
{vsn, "5.0.19"},
|
||||
{modules, []},
|
||||
{registered, [emqx_rule_engine_sup, emqx_rule_engine]},
|
||||
{applications, [kernel, stdlib, rulesql, getopt, emqx_ctl]},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{application, emqx_ee_bridge, [
|
||||
{description, "EMQX Enterprise data bridges"},
|
||||
{vsn, "0.1.14"},
|
||||
{vsn, "0.1.15"},
|
||||
{registered, []},
|
||||
{applications, [
|
||||
kernel,
|
||||
|
|
Loading…
Reference in New Issue