fix: bad error message when rule engine schema name is too long

Fixes:
https://emqx.atlassian.net/browse/EMQX-10778
This commit is contained in:
Kjell Winblad 2023-08-25 11:01:23 +02:00
parent aad9b1c27d
commit c65db82b07
2 changed files with 16 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{application, emqx_schema_registry, [
{description, "EMQX Schema Registry"},
{vsn, "0.1.5"},
{vsn, "0.1.6"},
{registered, [emqx_schema_registry_sup]},
{mod, {emqx_schema_registry_app, []}},
{included_applications, [

View File

@ -64,7 +64,7 @@ get_serde(SchemaName) ->
get_schema(SchemaName) ->
case
emqx_config:get(
[?CONF_KEY_ROOT, schemas, binary_to_atom(SchemaName)], undefined
[?CONF_KEY_ROOT, schemas, schema_name_bin_to_atom(SchemaName)], undefined
)
of
undefined ->
@ -333,6 +333,20 @@ async_delete_serdes(Names) ->
to_bin(A) when is_atom(A) -> atom_to_binary(A);
to_bin(B) when is_binary(B) -> B.
schema_name_bin_to_atom(Bin) when 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]
)
)
);
schema_name_bin_to_atom(Bin) ->
binary_to_atom(Bin, utf8).
-spec serde_to_map(serde()) -> serde_map().
serde_to_map(#serde{} = Serde) ->
#{