File 2008-erts-Print-more-complex-terms-in-crash-reason.patch of Package erlang

From 63b0880e714bd305033a7b07644bc87f8c949b66 Mon Sep 17 00:00:00 2001
From: Lukas Larsson <lukas@erlang.org>
Date: Thu, 2 Mar 2017 10:04:17 +0100
Subject: [PATCH] erts: Print more complex terms in crash reason

---
 erts/preloaded/src/init.erl | 39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/erts/preloaded/src/init.erl b/erts/preloaded/src/init.erl
index 86dc9a295..5c7cae3eb 100644
--- a/erts/preloaded/src/init.erl
+++ b/erts/preloaded/src/init.erl
@@ -263,21 +263,30 @@ boot(Start,Flags,Args) ->
     boot_loop(BootPid,State).
 
 %%% Convert a term to a printable string, if possible.
-to_string(X) when is_list(X) ->			% assume string
+to_string(X, D) when is_list(X), D < 4 ->			% assume string
     F = flatten(X, []),
     case printable_list(F) of
-	true ->  F;
-	false -> ""
+	true when length(F) > 0 ->  F;
+	_false ->
+            List = [to_string(E, D+1) || E <- X],
+            flatten(["[",join(List),"]"], [])
     end;
-to_string(X) when is_atom(X) ->
+to_string(X, _D) when is_list(X) ->
+    "[_]";
+to_string(X, _D) when is_atom(X) ->
     atom_to_list(X);
-to_string(X) when is_pid(X) ->
+to_string(X, _D) when is_pid(X) ->
     pid_to_list(X);
-to_string(X) when is_float(X) ->
+to_string(X, _D) when is_float(X) ->
     float_to_list(X);
-to_string(X) when is_integer(X) ->
+to_string(X, _D) when is_integer(X) ->
     integer_to_list(X);
-to_string(_X) ->
+to_string(X, D) when is_tuple(X), D < 4 ->
+    List = [to_string(E, D+1) || E <- tuple_to_list(X)],
+    flatten(["{",join(List),"}"], []);
+to_string(X, _D) when is_tuple(X) ->
+    "{_}";
+to_string(_X, _D) ->
     "".						% can't do anything with it
 
 %% This is an incorrect and narrow definition of printable characters.
@@ -291,6 +300,13 @@ printable_list([$\t|T]) -> printable_list(T);
 printable_list([]) -> true;
 printable_list(_) ->  false.
 
+join([] = T) ->
+    T;
+join([_Elem] = T) ->
+    T;
+join([Elem|T]) ->
+    [Elem,","|join(T)].
+
 flatten([H|T], Tail) when is_list(H) ->
     flatten(H, flatten(T, Tail));
 flatten([H|T], Tail) ->
@@ -299,7 +315,7 @@ flatten([], Tail) ->
     Tail.
 
 things_to_string([X|Rest]) ->
-    " (" ++ to_string(X) ++ ")" ++ things_to_string(Rest);
+    " (" ++ to_string(X, 0) ++ ")" ++ things_to_string(Rest);
 things_to_string([]) ->
     "".
 
@@ -307,9 +323,8 @@ halt_string(String, List) ->
     String ++ things_to_string(List).
 
 %% String = string()
-%% List = [string() | atom() | pid() | number()]
-%% Any other items in List, such as tuples, are ignored when creating
-%% the string used as argument to erlang:halt/1.
+%% List = [string() | atom() | pid() | number() | list() | tuple()]
+%% Items in List are truncated if found to be too large
 -spec crash(_, _) -> no_return().
 crash(String, List) ->
     halt(halt_string(String, List)).
-- 
2.12.2

openSUSE Build Service is sponsored by