Skip to content

Conversation

@umaannamalai
Copy link
Contributor

In some cases, caught exceptions passed to notice_error() are singular class errors and not iterables like the notice_error() logic currently expects. This PR updates logic to check if the errors passed to the API exist and are fully populated iterables before grabbing sys.exc_info() instead.

@github-actions
Copy link

github-actions bot commented Oct 31, 2025

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ ACTION actionlint 7 0 0 1.06s
✅ MARKDOWN markdownlint 7 0 0 0 1.32s
✅ PYTHON ruff 948 0 0 0 1.0s
✅ PYTHON ruff-format 948 0 0 0 0.4s
✅ YAML prettier 15 0 0 0 1.54s
✅ YAML v8r 15 0 0 4.61s
✅ YAML yamllint 15 0 0 0.69s

See detailed reports in MegaLinter artifacts

MegaLinter is graciously provided by OX Security

@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2025

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.78%. Comparing base (2dd463d) to head (71703bc).

Files with missing lines Patch % Lines
newrelic/core/stats_engine.py 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1564      +/-   ##
==========================================
+ Coverage   81.76%   81.78%   +0.01%     
==========================================
  Files         207      207              
  Lines       23953    23961       +8     
  Branches     3799     3799              
==========================================
+ Hits        19585    19596      +11     
+ Misses       3101     3098       -3     
  Partials     1267     1267              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@umaannamalai umaannamalai marked this pull request as ready for review November 3, 2025 17:49
@umaannamalai umaannamalai requested a review from a team as a code owner November 3, 2025 17:49
@umaannamalai umaannamalai merged commit b9d9d3b into main Nov 3, 2025
63 checks passed
@umaannamalai umaannamalai deleted the fix-notice-error-bug branch November 3, 2025 20:40

# If no exception to report, exit
if not error or None in error:
if not error or none_in_error(error) or (error and not error_is_iterable(error)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should only ever deal with the output of sys.exc_info, which is guaranteed to be a tuple of (None, None, None) or (exc, val, tb). This line is adding a bunch of unnecessary complexity when the original code here should have been fine.

if not error or None in error:
# Pull from sys.exc_info() if no exception is passed
# Check that the error exists and that it is a fully populated iterable
if not error or none_in_error(error) or (error and not error_is_iterable(error)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the intent of this change is to make it possible to pass in an instance of BaseException to be able to report it then this change is overcomplicated and unfortunately looks to be introducing a bug.

Take for example this code:

try:
    raise ValueError()
except ValueError as exc1:
    pass

try:
    raise TypeError()
except TypeError as exc2:
    notice_error(exc1)

Previously the exception instance was not allowed as an input, and would have caused an error that would crash.

With this PR's changes instead, it silently reports the wrong exception. The user is trying to pass in an exception to report, but as written this will trigger a pull from sys.exc_info() which will yield back the tuple for exc2, instead of exc1 which was passed in.

There's also a lot of complexity in these if statements now that I don't care for, as well as a bunch of new function calls that add overhead. Instead, I propose we construct a tuple in the form we expect from the exception instance if and only if the error passed in is an instance of BaseException and it has a non None __traceback__ attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants