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

BedTool.filter silently ignoring exceptions #231

Closed
pkaleta opened this issue Nov 23, 2017 · 2 comments
Closed

BedTool.filter silently ignoring exceptions #231

pkaleta opened this issue Nov 23, 2017 · 2 comments

Comments

@pkaleta
Copy link

pkaleta commented Nov 23, 2017

Here's an example that demonstrates the issue:

In [76]: def foo(x):
    raise ValueError('foo')
   ....:

In [77]: list(bed.filter(foo))
Out[77]: []

In [78]: [x for x in bed if foo(x)]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-78-3c60a1efa4e0> in <module>()
----> 1 [x for x in bed if foo(x)]

<ipython-input-76-45cfbd08b10a> in foo(x)
      1 def foo(x):
----> 2     raise ValueError('foo')
      3

ValueError: foo

As you can see, when using filter the exception is ignored somewhere along the way. I believe that the reason is that you're catching ValueError here: https://github.com/daler/pybedtools/blob/master/pybedtools/cbedtools.pyx#L760

@daler
Copy link
Owner

daler commented Nov 27, 2017

Thanks for reporting. I agree, that except (StopIteration, ValueError): is the likely culprit. That's part of a fix for a Cython idiosyncrasy (that was really tricky to pin down at the time) and I hesitate to change it without extensive testing.

Maybe as an alternative, BedTool.filter could wrap the incoming function, and the wrapper could replace any exceptions with FilterFunctionError that wouldn't get trapped by IntervalIterator.__next__?

daler added a commit that referenced this issue Nov 23, 2018
@daler
Copy link
Owner

daler commented Nov 23, 2018

Addressed in #264

@daler daler closed this as completed Nov 23, 2018
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

No branches or pull requests

2 participants