Skip to content

Commit 5766371

Browse files
committed
fix-traceback-in-plain-mode
1 parent cbac235 commit 5766371

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

IPython/core/ultratb.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,7 @@ def _format_exception_only(
364364
)
365365
)
366366

367-
try:
368-
assert hasattr(value, "msg")
369-
s = value.msg
370-
except Exception:
371-
s = self._some_str(value)
367+
s = self._some_str(value)
372368
if s:
373369
output_list.append(
374370
theme_table[self._theme_name].format(

tests/test_ultratb.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,20 @@ def test_plain_reports_notes(self):
437437
ip.run_cell("%xmode Verbose")
438438

439439

440+
class ExceptionMessagePreferenceTest(unittest.TestCase):
441+
"""
442+
Test that exception string representation is preferred over .msg attribute
443+
for non-SyntaxError exceptions in %xmode plain.
444+
"""
445+
446+
def test_jsondecodeerror_message(self):
447+
cell = "import json;json.loads('{\"a\": }')"
448+
expected = "JSONDecodeError: Expecting value: line 1 column 7 (char 6)"
449+
ip.run_cell("%xmode plain")
450+
with tt.AssertPrints(expected):
451+
ip.run_cell(cell)
452+
ip.run_cell("%xmode context")
453+
440454
# ----------------------------------------------------------------------------
441455

442456

0 commit comments

Comments
 (0)