Преглед изворни кода

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

Fixes:
https://emqx.atlassian.net/browse/EMQX-10778
Kjell Winblad пре 2 година
родитељ
комит
c65db82b07

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

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

+ 15 - 1
apps/emqx_schema_registry/src/emqx_schema_registry.erl

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