Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only format exception for primary context #2388

Merged
merged 1 commit into from
Apr 10, 2023

Conversation

agoose77
Copy link
Collaborator

@agoose77 agoose77 commented Apr 10, 2023

We were previously formatting exceptions for each context manager, which is clearly wrong! (oops)

This PR course corrects, and ensures that only the primary context actually tries to format the exception.

Fixes #2386

@agoose77 agoose77 requested a review from jpivarski April 10, 2023 19:49
@codecov
Copy link

codecov bot commented Apr 10, 2023

Codecov Report

Merging #2388 (988ad34) into main (be60b53) will decrease coverage by 0.01%.
The diff coverage is 50.00%.

Additional details and impacted files
Impacted Files Coverage Δ
src/awkward/_errors.py 80.00% <50.00%> (-0.49%) ⬇️

@agoose77 agoose77 temporarily deployed to docs-preview April 10, 2023 20:07 — with GitHub Actions Inactive
@jpivarski
Copy link
Member

It's fixed!

>>> import awkward as ak
>>> no_fields = ak.Array([[{}, {}], [], [{}]])
>>> no_fields["new_field"] = 123
Traceback (most recent call last):
  File "/home/jpivarski/irishep/awkward/src/awkward/highlevel.py", line 1025, in __setitem__
    self._layout = ak.operations.with_field(
  File "/home/jpivarski/irishep/awkward/src/awkward/operations/ak_with_field.py", line 47, in with_field
    return _impl(array, what, where, highlevel, behavior)
  File "/home/jpivarski/irishep/awkward/src/awkward/operations/ak_with_field.py", line 87, in _impl
    raise ValueError("no tuples or records in array; cannot add a new field")
ValueError: no tuples or records in array; cannot add a new field

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jpivarski/irishep/awkward/src/awkward/highlevel.py", line 1028, in __setitem__
    self._numbaview = None
  File "/home/jpivarski/irishep/awkward/src/awkward/_errors.py", line 54, in __exit__
    self.handle_exception(exception_type, exception_value)
  File "/home/jpivarski/irishep/awkward/src/awkward/_errors.py", line 64, in handle_exception
    raise self.decorate_exception(cls, exception)
ValueError: no tuples or records in array; cannot add a new field

This error occurred while calling

    ak.Array.__setitem__(
        self = <Array [[{}, {}], [], [{}]] type='3 * var * {}'>
        field_name = 'new_field'
        field_value = 123
    )

(And the above wouldn't even be an error in main.)

@jpivarski jpivarski merged commit 265f632 into main Apr 10, 2023
@jpivarski jpivarski deleted the agoose77/fix-reentrant-context branch April 10, 2023 20:41
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.

Error message handling should only show the primary ErrorContext
2 participants