Skip to content

Commit 2480dec

Browse files
authored
Revert "Fix notice_error logic for non-iterable exceptions. (#1564)"
This reverts commit b9d9d3b.
1 parent b9d9d3b commit 2480dec

File tree

3 files changed

+6
-38
lines changed

3 files changed

+6
-38
lines changed

newrelic/api/time_trace.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,23 +360,16 @@ def _observe_exception(self, exc_info=None, ignore=None, expected=None, status_c
360360
return fullname, message, message_raw, tb, is_expected
361361

362362
def notice_error(self, error=None, attributes=None, expected=None, ignore=None, status_code=None):
363-
def error_is_iterable(error):
364-
return hasattr(error, "__iter__") and not isinstance(error, (str, bytes))
365-
366-
def none_in_error(error):
367-
return error_is_iterable(error) and None in error
368-
369363
attributes = attributes if attributes is not None else {}
370364

371365
# If no exception details provided, use current exception.
372366

373-
# Pull from sys.exc_info() if no exception is passed
374-
# Check that the error exists and that it is a fully populated iterable
375-
if not error or none_in_error(error) or (error and not error_is_iterable(error)):
367+
# Pull from sys.exc_info if no exception is passed
368+
if not error or None in error:
376369
error = sys.exc_info()
377370

378371
# If no exception to report, exit
379-
if not error or none_in_error(error) or (error and not error_is_iterable(error)):
372+
if not error or None in error:
380373
return
381374

382375
exc, value, tb = error

newrelic/core/stats_engine.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -676,14 +676,9 @@ def record_time_metrics(self, metrics):
676676
self.record_time_metric(metric)
677677

678678
def notice_error(self, error=None, attributes=None, expected=None, ignore=None, status_code=None):
679-
def error_is_iterable(error):
680-
return hasattr(error, "__iter__") and not isinstance(error, (str, bytes))
681-
682-
def none_in_error(error):
683-
return error_is_iterable(error) and None in error
684-
685679
attributes = attributes if attributes is not None else {}
686680
settings = self.__settings
681+
687682
if not settings:
688683
return
689684

@@ -696,12 +691,11 @@ def none_in_error(error):
696691
return
697692

698693
# Pull from sys.exc_info if no exception is passed
699-
# Check that the error exists and that it is a fully populated iterable
700-
if not error or none_in_error(error) or (error and not error_is_iterable(error)):
694+
if not error or None in error:
701695
error = sys.exc_info()
702696

703697
# If no exception to report, exit
704-
if not error or none_in_error(error) or (error and not error_is_iterable(error)):
698+
if not error or None in error:
705699
return
706700

707701
exc, value, tb = error

tests/agent_features/test_notice_error.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,6 @@
3939

4040
# =============== Test errors during a transaction ===============
4141

42-
_key_error_name = callable_name(KeyError)
43-
44-
_test_notice_error_exception_object = [(_key_error_name, "'f'")]
45-
46-
47-
@validate_transaction_errors(errors=_test_notice_error_exception_object)
48-
@background_task()
49-
def test_notice_error_non_iterable_object():
50-
"""Test that notice_error works when passed an exception object directly"""
51-
try:
52-
test_dict = {"a": 4, "b": 5}
53-
# Force a KeyError
54-
test_dict["f"]
55-
except KeyError as e:
56-
# The caught exception here is a non-iterable, singular KeyError object with no associated traceback
57-
# This will exercise logic to pull from sys.exc_info() instead of using the exception directly
58-
notice_error(e)
59-
60-
6142
_test_notice_error_sys_exc_info = [(_runtime_error_name, "one")]
6243

6344

0 commit comments

Comments
 (0)