File 2391-erl_error-Print-nice-messages-for-badmap-and-badkey-.patch of Package erlang

From b3c1d1e5f12408827b3ada623dc02e7d45db4ec0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Thu, 29 Oct 2020 10:00:44 +0100
Subject: [PATCH] erl_error: Print nice messages for badmap and badkey
 exceptions

---
 lib/stdlib/src/erl_error.erl    | 4 ++++
 lib/stdlib/test/shell_SUITE.erl | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/lib/stdlib/src/erl_error.erl b/lib/stdlib/src/erl_error.erl
index 5fbf5a6282..9ee4a3c440 100644
--- a/lib/stdlib/src/erl_error.erl
+++ b/lib/stdlib/src/erl_error.erl
@@ -150,6 +150,10 @@ explain_reason(badarg, error, [], _PF, _S, _Enc, _CL) ->
     <<"bad argument">>;
 explain_reason({badarg,V}, error=Cl, [], PF, S, _Enc, CL) -> % orelse, andalso
     format_value(V, <<"bad argument: ">>, Cl, PF, S, CL);
+explain_reason({badkey,V}, error=Cl, [], PF, S, _Enc, CL) ->
+    format_value(V, <<"bad key: ">>, Cl, PF, S, CL);
+explain_reason({badmap,V}, error=Cl, [], PF, S, _Enc, CL) ->
+    format_value(V, <<"bad map: ">>, Cl, PF, S, CL);
 explain_reason(badarith, error, [], _PF, _S, _Enc, _CL) ->
     <<"an error occurred when evaluating an arithmetic expression">>;
 explain_reason({badarity,{Fun,As}}, error, [], _PF, _S, Enc, _CL)
diff --git a/lib/stdlib/test/shell_SUITE.erl b/lib/stdlib/test/shell_SUITE.erl
index 4d7a2ea078..d6110270b4 100644
--- a/lib/stdlib/test/shell_SUITE.erl
+++ b/lib/stdlib/test/shell_SUITE.erl
@@ -2344,6 +2344,10 @@ otp_6554(Config) when is_list(Config) ->
         comm_err(<<"fun(X) -> not X end(a).">>),
     "exception error: bad argument: a" =
         comm_err(<<"fun(A, B) -> A orelse B end(a, b).">>),
+    "exception error: bad key: key" =
+        comm_err(<<"map_get(key, #{}).">>),
+    "exception error: bad map: not_a_map" =
+        comm_err(<<"map_get(key, not_a_map).">>),
     "exception error: an error occurred when evaluating an arithmetic expression" =
         comm_err(<<"math:sqrt(2)/round(math:sqrt(0)).">>),
     "exception error: interpreted function with arity 1 called with no arguments" =
-- 
2.26.2

openSUSE Build Service is sponsored by