This patch adds support for chained exceptions and utilizes those to provide a more seamless experience for both cli and api users by providing them with original exceptions and their tracebacks.
This likely makes isolate's stringized_traceback obsolete.
For example:
import fal
class FooException(Exception):
pass
class BarException(Exception):
pass
def bar():
raise BarException("bar")
def foo():
try:
bar()
except Exception as exc:
raise FooException("foo") from exc
@fal.function()
def mytest():
foo()
print(str(2*2))
if __name__ == "__main__":
mytest()
running it through API we'll get (note that not only traceback is present but also __cause__ is correctly set):
Traceback (most recent call last):
File "/Users/efiop/git/efiop/ui-comp/fal/exc_chain.py", line 15, in foo
bar()
^^^^^^^^
File "/Users/efiop/git/efiop/ui-comp/fal/exc_chain.py", line 11, in bar
raise BarException("bar")
^^^^^^^^^^^^^^^^^
BarException: bar
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/efiop/git/efiop/ui-comp/fal/exc_chain.py", line 25, in <module>
mytest()
File "/Users/efiop/git/efiop/fal/projects/fal/src/fal/api.py", line 978, in __call__
raise cause
File "/Users/efiop/git/efiop/ui-comp/fal/exc_chain.py", line 21, in mytest
foo()
^^^^
File "/Users/efiop/git/efiop/ui-comp/fal/exc_chain.py", line 17, in foo
raise FooException("foo") from exc
^^^^^^^^^^^^^^^^^
FooException: foo
and with fal fn run (no --debug) we'll get
NOTE: we now support chained exceptions, but their classes are recreated because we dill everything by value and not by reference. This is better than before, but not perfect yet. See #142
[x] check if we can hide raise cause in api case (probably can catch and reraise higher)(not easily as it is about future tb frames, so not worth it for now)
This patch adds support for chained exceptions and utilizes those to provide a more seamless experience for both cli and api users by providing them with original exceptions and their tracebacks.
This likely makes isolate's
stringized_traceback
obsolete.For example:
running it through API we'll get (note that not only traceback is present but also
__cause__
is correctly set):and with
fal fn run
(no--debug
) we'll getNOTE: we now support chained exceptions, but their classes are recreated because we
dill
everything by value and not by reference. This is better than before, but not perfect yet. See #142