Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Catching exceptions from iterator MoveNext() (related to #475) #523

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

Closed
wants to merge 13 commits into from

Conversation

rickardraysearch
Copy link
Contributor

What does this implement/fix? Explain your changes.

Catches exceptions in iterator MoveNext() and throws them in python instead of crashing.

Does this close any currently open issues?

Issue #475

Any other comments?

...

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

@codecov
Copy link

codecov bot commented Aug 9, 2017

Codecov Report

Merging #523 into master will decrease coverage by 7.48%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #523      +/-   ##
==========================================
- Coverage    76.9%   69.42%   -7.49%     
==========================================
  Files          63        1      -62     
  Lines        5582      278    -5304     
  Branches      890        0     -890     
==========================================
- Hits         4293      193    -4100     
+ Misses        998       85     -913     
+ Partials      291        0     -291
Flag Coverage Δ
#setup_linux 69.42% <ø> (ø) ⬆️
#setup_windows ?
Impacted Files Coverage Δ
setup.py 69.42% <0%> (-17.99%) ⬇️
src/runtime/arrayobject.cs
src/runtime/pyansistring.cs
src/runtime/classobject.cs
src/runtime/CustomMarshaler.cs
src/runtime/fieldobject.cs
src/runtime/generictype.cs
src/runtime/extensiontype.cs
src/runtime/Util.cs
src/runtime/importhook.cs
... and 52 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 545c549...e40995c. Read the comment docs.

@rickardraysearch
Copy link
Contributor Author

rickardraysearch commented Aug 10, 2017

For future reference, the only place where a general "catch (Exception E)" and subsequent Exceptions.SetError() is done without throwing away the outermost exception is in TypeMethod.Invoke.

@den-run-ai
Copy link
Contributor

@rickardraysearch can you clarify about that TypeMethod.Invoke? Is this an issue or just a note?

@rickardraysearch
Copy link
Contributor Author

@denfromufa , I only wanted to note that the usage is not completely consistent across all invocations of Exceptions.SetError(). When we revisit how to do the SetErrors, I want to remember this without having to find it out again.

@den-run-ai
Copy link
Contributor

@filmor @vmuriart please review!

@vmuriart
Copy link
Contributor

What happens if you call next() after the exception is thrown? Might be worth adding a test for it to make sure it has expected behavior.

Other than adding that test, ok to merge

@den-run-ai
Copy link
Contributor

What happens if you call next() after the exception is thrown? Might be worth adding a test for it to make sure it has expected behavior.

Other than adding that test, ok to merge

@vmuriart did you mean calling this part twice?

with pytest.raises(OverflowException) as cm:
    next(val)

@den-run-ai
Copy link
Contributor

@vmuriart or did you mean to verify this behavior?

https://stackoverflow.com/a/11366139/2230844

@vmuriart
Copy link
Contributor

vmuriart commented Sep 6, 2017

both :).

@den-run-ai
Copy link
Contributor

@rickardraysearch can you please address the suggestions from @vmuriart and then we can merge this!

@ArvidJB
Copy link
Contributor

ArvidJB commented Jun 21, 2018

We just ran into the same issue that this pull request is going to fix. Is there any particular reason this was never merged? If there is further work to be done we would be happy to help.

@den-run-ai
Copy link
Contributor

@ArvidJB i just updated this branch with latest master and CI tests look good. You can add 2 additional unit tests suggested by @vmuriart but personally I approved this PR. If one more core developers approves, then we can merge this. @filmor had a question and that probably can be addressed in another PR.

@ArvidJB
Copy link
Contributor

ArvidJB commented Jun 25, 2018

@denfromufa / @vmuriart I think this boils down to adding the following lines

    # after exception is thrown iterator is no longer valid
    with pytest.raises(StopIteration):
        next(val)

to test_iteration_innerexception. Should I create a new pull request for that or would you be willing to add those lines to @rickardraysearch 's request?
I tested @rickardraysearch 's changes and they work as intended.

@den-run-ai
Copy link
Contributor

@ArvidJB please fork @rickardraysearch branch and make a new pull request with your changes. If you PR looks good, then we can close this PR.

@ArvidJB
Copy link
Contributor

ArvidJB commented Jun 25, 2018

@denfromufa I just submitted #693 with the enhanced testing

filmor added a commit that referenced this pull request Jun 26, 2018
Catching exceptions from iterator MoveNext(), additional testing (issue #475, original pull request #523)
@filmor
Copy link
Member

filmor commented Jun 26, 2018

Merged as #693.

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