fix: use explain instead of msg as error explanation and add test
This commit is contained in:
parent
9d7acc6a32
commit
9b089a4e5a
|
@ -74,7 +74,7 @@ handle_rule_function(schema_decode, [SchemaId, Data | MoreArgs]) ->
|
||||||
schema_id => SchemaId,
|
schema_id => SchemaId,
|
||||||
data => Data,
|
data => Data,
|
||||||
more_args => MoreArgs,
|
more_args => MoreArgs,
|
||||||
msg =>
|
explain =>
|
||||||
<<"The given data could not be decoded. Please check the input data and the schema.">>
|
<<"The given data could not be decoded. Please check the input data and the schema.">>
|
||||||
}}
|
}}
|
||||||
)
|
)
|
||||||
|
|
|
@ -44,7 +44,8 @@ sparkplug_tests() ->
|
||||||
t_sparkplug_decode,
|
t_sparkplug_decode,
|
||||||
t_sparkplug_encode,
|
t_sparkplug_encode,
|
||||||
t_sparkplug_decode_encode_with_message_name,
|
t_sparkplug_decode_encode_with_message_name,
|
||||||
t_sparkplug_encode_float_to_uint64_key
|
t_sparkplug_encode_float_to_uint64_key,
|
||||||
|
t_decode_fail
|
||||||
].
|
].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
|
@ -532,6 +533,23 @@ t_encode(Config) ->
|
||||||
end,
|
end,
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
t_decode_fail(_Config) ->
|
||||||
|
SerdeName = my_serde,
|
||||||
|
SerdeType = protobuf,
|
||||||
|
ok = create_serde(SerdeType, SerdeName),
|
||||||
|
Payload = <<"ss">>,
|
||||||
|
?assertThrow(
|
||||||
|
{schema_decode_error, #{
|
||||||
|
data := <<"ss">>,
|
||||||
|
error_type := decoding_failure,
|
||||||
|
explain := _,
|
||||||
|
more_args := [<<"Person">>],
|
||||||
|
schema_id := <<"my_serde">>
|
||||||
|
}},
|
||||||
|
emqx_rule_funcs:schema_decode(<<"my_serde">>, Payload, <<"Person">>)
|
||||||
|
),
|
||||||
|
ok.
|
||||||
|
|
||||||
t_decode(Config) ->
|
t_decode(Config) ->
|
||||||
SerdeType = ?config(serde_type, Config),
|
SerdeType = ?config(serde_type, Config),
|
||||||
SerdeName = my_serde,
|
SerdeName = my_serde,
|
||||||
|
|
Loading…
Reference in New Issue