Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,7 @@ def get_errno(exc_value):

def get_error_message(exc_value):
# type: (Optional[BaseException]) -> str
message = safe_str(
getattr(exc_value, "message", "")
or getattr(exc_value, "detail", "")
or safe_str(exc_value)
) # type: str
message = safe_str(exc_value)

# __notes__ should be a list of strings when notes are added
# via add_note, but can be anything else if __notes__ is set
Expand Down
6 changes: 3 additions & 3 deletions tests/test_exceptiongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_exceptiongroup():
"type": "chained",
},
"type": "ExceptionGroup",
"value": "imports",
"value": "imports (2 sub-exceptions)",
},
{
"mechanism": {
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_exceptiongroup():
"type": "test_suite",
},
"type": "ExceptionGroup",
"value": "nested",
"value": "nested (3 sub-exceptions)",
},
]

Expand Down Expand Up @@ -183,7 +183,7 @@ def test_exceptiongroup_simple():
}

assert exception_values[1]["type"] == "ExceptionGroup"
assert exception_values[1]["value"] == "simple"
assert exception_values[1]["value"] == "simple (1 sub-exception)"
assert exception_values[1]["mechanism"] == {
"type": "test_suite",
"handled": False,
Expand Down
17 changes: 8 additions & 9 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,15 +644,14 @@ def test_is_sentry_url_no_client():
],
)
def test_get_error_message(error, expected_result):
with pytest.raises(BaseException) as exc_value:
exc_value.message = error
raise Exception
assert get_error_message(exc_value) == expected_result(exc_value)

with pytest.raises(BaseException) as exc_value:
exc_value.detail = error
raise Exception
assert get_error_message(exc_value) == expected_result(exc_value)
class CustomException(Exception):
def __str__(self):
return expected_result(self)

with pytest.raises(CustomException) as exc:
raise CustomException

assert get_error_message(exc.value) == expected_result(exc.value)


def test_safe_str_fails():
Expand Down