diff options
Diffstat (limited to 'lib/kernel/src/erl_erts_errors.erl')
-rw-r--r-- | lib/kernel/src/erl_erts_errors.erl | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/lib/kernel/src/erl_erts_errors.erl b/lib/kernel/src/erl_erts_errors.erl index 8b0768ac80..66fcd1bb0b 100644 --- a/lib/kernel/src/erl_erts_errors.erl +++ b/lib/kernel/src/erl_erts_errors.erl @@ -19,7 +19,7 @@ %% -module(erl_erts_errors). --export([format_error/2]). +-export([format_error/2, format_bs_fail/2]). -spec format_error(Reason, StackTrace) -> ErrorMap when Reason :: term(), @@ -43,6 +43,24 @@ format_error(Reason, [{M,F,As,Info}|_]) -> end, format_error_map(Res, 1, #{}). +-spec format_bs_fail(Reason, StackTrace) -> ErrorMap when + Reason :: term(), + StackTrace :: erlang:stacktrace(), + ErrorMap :: #{'general' => unicode:chardata()}. + +format_bs_fail(Reason, [{_,_,_,Info}|_]) -> + ErrorInfoMap = proplists:get_value(error_info, Info, #{}), + case ErrorInfoMap of + #{cause := {Segment,Type,Error}} -> + Str0 = do_format_bs_fail( Reason, Type, Error), + Str1 = io_lib:format("failed constructing binary: segment ~p, type '~ts': ~ts", + [Segment,Type,Str0]), + Str = iolist_to_binary(Str1), + #{general => Str}; + #{} -> + #{} + end. + format_atomics_error(new, [Size,Options], Reason, Cause) -> case Reason of system_limit -> @@ -1027,6 +1045,40 @@ format_erlang_error(whereis, [_], _) -> format_erlang_error(_, _, _) -> []. +do_format_bs_fail(system_limit, _Type, size) -> + <<"the size is too large">>; +do_format_bs_fail(badarg, Type, Info) -> + do_format_bs_fail(Type, Info). + +do_format_bs_fail(float, invalid) -> + <<"the size is not one of the supported sizes (16, 32, or 64)">>; +do_format_bs_fail(float, no_float) -> + <<"the integer is outside the range expressible as a float of the given size">>; +do_format_bs_fail(binary, unit) -> + <<"the size of the given binary/bitstring is not a multiple of the unit for the segment">>; +do_format_bs_fail(_Type, short) -> + <<"the given binary/bitstring is shorter than the size of the segment">>; +do_format_bs_fail(_Type, negative_size) -> + <<"the size is negative">>; +do_format_bs_fail(_Type, size) -> + <<"the size is not an integer">>; +do_format_bs_fail(Type, type) -> + <<"not a", + (case Type of + binary -> + <<" binary">>; + float -> + <<" float or an integer">>; + integer -> + <<"n integer">>; + _ -> + <<"n integer encodable as ", (atom_to_binary(Type))/binary>> + end)/binary>>. + +%%% +%%% Utility functions. +%%% + list_to_something(List, Error) -> try length(List) of _ -> |