diff --git a/apps/emqx/etc/vm.args.cloud b/apps/emqx/etc/vm.args.cloud index 175896a8fc8..8602d16398c 100644 --- a/apps/emqx/etc/vm.args.cloud +++ b/apps/emqx/etc/vm.args.cloud @@ -128,3 +128,6 @@ ## Disable os_mon's disksup by default -os_mon start_disksup false + +## Sets unicode as the printable character range when formatting binaries ++pc unicode diff --git a/apps/emqx_utils/src/emqx_utils.erl b/apps/emqx_utils/src/emqx_utils.erl index 87f0f7cf64e..ec006203b85 100644 --- a/apps/emqx_utils/src/emqx_utils.erl +++ b/apps/emqx_utils/src/emqx_utils.erl @@ -569,7 +569,7 @@ tcp_keepalive_opts(OS, _Idle, _Interval, _Probes) -> {error, {unsupported_os, OS}}. format(Term) -> - unicode:characters_to_binary(io_lib:format("~0p", [Term])). + unicode:characters_to_binary(io_lib:format("~0tp", [Term])). format(Fmt, Args) -> unicode:characters_to_binary(io_lib:format(Fmt, Args)). diff --git a/apps/emqx_utils/test/emqx_utils_tests.erl b/apps/emqx_utils/test/emqx_utils_tests.erl index 8664cde6c64..e39f01fc422 100644 --- a/apps/emqx_utils/test/emqx_utils_tests.erl +++ b/apps/emqx_utils/test/emqx_utils_tests.erl @@ -50,3 +50,30 @@ foldl_while_test_() -> ) ) ]. + +to_binary_representation(Bin) when is_binary(Bin) -> + Bytes = binary_to_list(Bin), + iolist_to_binary([ + [$<, $<], + lists:join($,, [ + integer_to_binary(B) + || B <- Bytes + ]), + [$>, $>] + ]). + +readable_error_msg_test_() -> + [ + {"binary in nested structure with non-latin1 characters", + ?_assert(begin + %% An unexpected error that could occur and be returned via HTTP API. + Text = <<"test中文"/utf8>>, + Error = {badmatch, #{description => Text}}, + %% Output shouldn't contain the "exploded" bytes + Exploded = to_binary_representation(Text), + Formatted = emqx_utils:readable_error_msg(Error), + %% Precondition: `+pc unicode' must be set on the VM. + ?assertEqual(unicode, io:printable_range()), + nomatch =:= re:run(Formatted, Exploded, [{capture, all, binary}]) + end)} + ]. diff --git a/changes/ce/feat-14072.en.md b/changes/ce/feat-14072.en.md new file mode 100644 index 00000000000..c1a040bd0c2 --- /dev/null +++ b/changes/ce/feat-14072.en.md @@ -0,0 +1 @@ +Changed the virtual machine printable range to unicode. This means that some binaries that previously had their byte representation printed in message will now be better formatted. For example, a binary that was once formatted as `<<116,101,115,116,228,184,173,230,150,135>>` will now be formatted as `<<"test中文"/utf8>>`. diff --git a/scripts/ensure-rebar3.sh b/scripts/ensure-rebar3.sh index 14b6ad7c733..ae877baa69a 100755 --- a/scripts/ensure-rebar3.sh +++ b/scripts/ensure-rebar3.sh @@ -10,7 +10,7 @@ case ${OTP_VSN} in VERSION="3.19.0-emqx-9" ;; 26*) - VERSION="3.20.0-emqx-1" + VERSION="3.20.0-emqx-5" ;; *) echo "Unsupported Erlang/OTP version $OTP_VSN"