-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Exception in first-class function called through typed list swallows exceptions #8246
Comments
Current implementation of first-class function is going through the cfunc wrapper and it is intentionally ignoring exception in this part of the code: Lines 201 to 211 in 88fef5b
This is probably not what user is expecting. We might need a new call wrapper just for first-class function. |
Edit: when I first wrote this, I didn't remember where but later found the link. Also, I don't quite remember where, but at one point not too long ago there was a discussion about a swallowed error when inline='always'. |
Is there any chance this could be labeled as a bug fix rather than a feature request? It's pretty surprising, diverges from plain-python behavior, and seems like it would be supported based on my interpretation of the documentation If not, that's fine. I was just hoping for this to be fixed sooner rather than later. :) |
Okay, this bug is officially vexing me... I'll offer a USD100 bounty, open through the end of 2022. :) |
I'm also interested in this getting fixed soon. Using This feels closer to correct for the lines @sklam pointed to: pyapi = self.get_python_api(builder)
gil_state = pyapi.gil_ensure()
self.call_conv.raise_error(builder, pyapi, status)
pyapi.gil_release(gil_state)
builder.ret(ir.Constant(ll_return_type, None)) With these changes made to the source, now consider this reproducer: from numba import njit, f8, types
from numba.typed import List
import pytest
@njit(f8(f8,f8))
def Divide(a, b):
if(a == 0):
raise ValueError("Bad a")
else:
return a / b
fn_typ = types.FunctionType(f8(f8,f8))
lst = List.empty_list(fn_typ)
lst.append(Divide)
@njit(cache=True)
def apply_it(lst,a,b):
for f in lst:
f(a,b)
apply_it(lst, 0,2)
print("SHOULD NOT GET RUN, PREVIOUS LINE SHOULD RAISE ERROR.") And the output: Traceback (most recent call last):
File "/home/danny/Projects/Cognitive-Rule-Engine/cre/garbage25.py", line 8, in Divide
raise ValueError("Bad a")
ValueError: Bad a
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/danny/Projects/Cognitive-Rule-Engine/cre/garbage25.py", line 23, in <module>
apply_it(lst, 0,2)
SystemError: CPUDispatcher(<function apply_it at 0x7efd077ba550>) returned a result with an error set So this still seem to not be quite right because there is perhaps something slightly off about the error... perhaps some return value isn't getting set to Null (that last line doesn't seem to be doing the trick)... and so python catches the improper error raise and then reraises it as a SystemError. Which is at least an error being raised, but also means you can't directly catch the error by type. |
As discussed in gitter
numba=0.55.1
python=3.7.1
windows10
Calling the first-class function from a jitted function causes the exception to be swallowed.
The exception terminates the program as expected when called from plain python.
The text was updated successfully, but these errors were encountered: