fix: make protobuf schema decode error reported to user less cryptic
Before this commit the user would see a cryptic warning log including function_clause when decoding a message failed. This commit improves this by removing function_caluse as well as some other cryptic words from the message and adding a description describing what went wrong. Fixes: https://emqx.atlassian.net/browse/EMQX-12453
This commit is contained in:
parent
40080f5e7d
commit
82800faadf
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_schema_registry, [
|
{application, emqx_schema_registry, [
|
||||||
{description, "EMQX Schema Registry"},
|
{description, "EMQX Schema Registry"},
|
||||||
{vsn, "0.3.0"},
|
{vsn, "0.3.1"},
|
||||||
{registered, [emqx_schema_registry_sup]},
|
{registered, [emqx_schema_registry_sup]},
|
||||||
{mod, {emqx_schema_registry_app, []}},
|
{mod, {emqx_schema_registry_app, []}},
|
||||||
{included_applications, [
|
{included_applications, [
|
||||||
|
|
|
@ -64,7 +64,21 @@ handle_rule_function(sparkplug_encode, [Term | MoreArgs]) ->
|
||||||
[?EMQX_SCHEMA_REGISTRY_SPARKPLUGB_SCHEMA_NAME, Term | MoreArgs]
|
[?EMQX_SCHEMA_REGISTRY_SPARKPLUGB_SCHEMA_NAME, Term | MoreArgs]
|
||||||
);
|
);
|
||||||
handle_rule_function(schema_decode, [SchemaId, Data | MoreArgs]) ->
|
handle_rule_function(schema_decode, [SchemaId, Data | MoreArgs]) ->
|
||||||
decode(SchemaId, Data, MoreArgs);
|
try
|
||||||
|
decode(SchemaId, Data, MoreArgs)
|
||||||
|
catch
|
||||||
|
error:{gpb_error, {decoding_failure, {_Data, _Schema, {error, function_clause, _Stack}}}} ->
|
||||||
|
throw(
|
||||||
|
{schema_decode_error, #{
|
||||||
|
error_type => decoding_failure,
|
||||||
|
schema_id => SchemaId,
|
||||||
|
data => Data,
|
||||||
|
more_args => MoreArgs,
|
||||||
|
msg =>
|
||||||
|
<<"The given data could not be decoded. Please check the input data and the schema.">>
|
||||||
|
}}
|
||||||
|
)
|
||||||
|
end;
|
||||||
handle_rule_function(schema_decode, Args) ->
|
handle_rule_function(schema_decode, Args) ->
|
||||||
error({args_count_error, {schema_decode, Args}});
|
error({args_count_error, {schema_decode, Args}});
|
||||||
handle_rule_function(schema_encode, [SchemaId, Term | MoreArgs]) ->
|
handle_rule_function(schema_encode, [SchemaId, Term | MoreArgs]) ->
|
||||||
|
|
Loading…
Reference in New Issue