Open jackos opened 1 year ago
Thanks for filing! The approach here is tricky, because we don't build our C++ code with exceptions. We'll keep this on the radar.
we don't build our C++ code with exceptions
FWIW, in general the exception shouldn't escape the pytorch/pybind11 module boundary. pytorch uses pybind11 exception translation, which should catch C++ exceptions and convert them to CPython exceptions.
This little demo seems to do what I expect: in a mojo try
block, exceptions from a pybind11-wrapped function are caught; without a mojo try
block the exception causes program exit.
It looks like the issue here may be that the backtrace handler (?) is trying to call __str__
on a pyobject which no longer exists (output below is: running the OP's code under lldb on github codespaces with mojo 0.3.1):
Update: now not a segfault, returning <NULL>
instead of raising an error
Bug description
If a C++ exception is thrown, that would normally result in Python catching the error and reporting it correctly, it results in a seg fault. e.g. the shape is incompatible here:
Results in seg fault:
Where doing this in Python returns the correct error:
May be related to all projects using C++ exceptions, or may just be the way PyTorch handles them being incompatible.
Discovered from: https://github.com/modularml/mojo/issues/974
System information