@@ -177,6 +177,22 @@ defmodule Exception do
177
177
end
178
178
end
179
179
180
+ @ doc false
181
+ @ spec _format_message_with_term ( String . t ( ) , any ) :: String . t ( )
182
+ def _format_message_with_term ( message , term ) do
183
+ inspected =
184
+ term
185
+ |> inspect ( pretty: true )
186
+ |> String . split ( "\n " )
187
+ |> Enum . map ( fn
188
+ "" -> ""
189
+ line -> " " <> line
190
+ end )
191
+ |> Enum . join ( "\n " )
192
+
193
+ message <> "\n \n " <> inspected
194
+ end
195
+
180
196
@ doc """
181
197
Attaches information to exceptions for extra debugging.
182
198
@@ -1431,7 +1447,10 @@ defmodule BadStructError do
1431
1447
1432
1448
@ impl true
1433
1449
def message ( exception ) do
1434
- "expected a struct named #{ inspect ( exception . struct ) } , got: #{ inspect ( exception . term ) } "
1450
+ Exception . _format_message_with_term (
1451
+ "expected a struct named #{ inspect ( exception . struct ) } , got:" ,
1452
+ exception . term
1453
+ )
1435
1454
end
1436
1455
end
1437
1456
@@ -1451,7 +1470,10 @@ defmodule BadMapError do
1451
1470
1452
1471
@ impl true
1453
1472
def message ( exception ) do
1454
- "expected a map, got: #{ inspect ( exception . term ) } "
1473
+ Exception . _format_message_with_term (
1474
+ "expected a map, got:" ,
1475
+ exception . term
1476
+ )
1455
1477
end
1456
1478
end
1457
1479
@@ -1470,7 +1492,10 @@ defmodule BadBooleanError do
1470
1492
1471
1493
@ impl true
1472
1494
def message ( exception ) do
1473
- "expected a boolean on left-side of \" #{ exception . operator } \" , got: #{ inspect ( exception . term ) } "
1495
+ Exception . _format_message_with_term (
1496
+ "expected a boolean on left-side of \" #{ exception . operator } \" , got:" ,
1497
+ exception . term
1498
+ )
1474
1499
end
1475
1500
end
1476
1501
@@ -1492,7 +1517,10 @@ defmodule MatchError do
1492
1517
1493
1518
@ impl true
1494
1519
def message ( exception ) do
1495
- "no match of right hand side value: #{ inspect ( exception . term ) } "
1520
+ Exception . _format_message_with_term (
1521
+ "no match of right hand side value:" ,
1522
+ exception . term
1523
+ )
1496
1524
end
1497
1525
end
1498
1526
@@ -1518,7 +1546,10 @@ defmodule CaseClauseError do
1518
1546
1519
1547
@ impl true
1520
1548
def message ( exception ) do
1521
- "no case clause matching: #{ inspect ( exception . term ) } "
1549
+ Exception . _format_message_with_term (
1550
+ "no case clause matching:" ,
1551
+ exception . term
1552
+ )
1522
1553
end
1523
1554
end
1524
1555
@@ -1548,7 +1579,10 @@ defmodule WithClauseError do
1548
1579
1549
1580
@ impl true
1550
1581
def message ( exception ) do
1551
- "no with clause matching: #{ inspect ( exception . term ) } "
1582
+ Exception . _format_message_with_term (
1583
+ "no with clause matching:" ,
1584
+ exception . term
1585
+ )
1552
1586
end
1553
1587
end
1554
1588
@@ -1598,7 +1632,10 @@ defmodule TryClauseError do
1598
1632
1599
1633
@ impl true
1600
1634
def message ( exception ) do
1601
- "no try clause matching: #{ inspect ( exception . term ) } "
1635
+ Exception . _format_message_with_term (
1636
+ "no try clause matching:" ,
1637
+ exception . term
1638
+ )
1602
1639
end
1603
1640
end
1604
1641
@@ -2160,7 +2197,10 @@ defmodule KeyError do
2160
2197
"make sure to add parentheses after the function name)"
2161
2198
2162
2199
true ->
2163
- message <> " in: #{ inspect ( term , pretty: true , limit: :infinity ) } "
2200
+ Exception . _format_message_with_term (
2201
+ message <> " in:" ,
2202
+ term
2203
+ )
2164
2204
end
2165
2205
end
2166
2206
@@ -2202,7 +2242,7 @@ defmodule KeyError do
2202
2242
2203
2243
case suggestions do
2204
2244
[ ] -> [ ]
2205
- suggestions -> [ ". Did you mean:\n \n " | format_suggestions ( suggestions ) ]
2245
+ suggestions -> [ "\n \n Did you mean:\n \n " | format_suggestions ( suggestions ) ]
2206
2246
end
2207
2247
end
2208
2248
0 commit comments