Tracebacks in Jupyter notebooks¶
Andreas Freise, 16/04/2020
The following demonstrates how Finesse handles parse errors. When run from IPython or Jupyter the full traceback is suppressed and only the parser error itself is shown. When run from Python it always returns the full traceback.
You can print the latest full traceback with finesse.tb().
If you want to always see the full traceback, for example, during debugging, you can set this with finesse.show_tracebacks()
We use a very simple example model for the demonstration:
from finesse.env import is_interactive
print(is_interactive())
True
import finesse
code = """
l laser P=1
pd tmp laser.p1.o
"""
kat = finesse.Model()
kat.parse(code)
A syntax error in the katscript gives a parser error:
code = """
l1 laser P=1
pd tmp laser.p1.o
"""
kat = finesse.Model()
kat.parse(code)
KatSyntaxError: (use finesse.tb() to see the full traceback)
line 2: unknown element 'l1'. Did you mean 'l'?
1:
-->2: l1 laser P=1
^^
3: pd tmp laser.p1.o
code = """
l1 laser P=1
pd tmp laser.p1.o
"""
kat = finesse.Model()
kat.parse(code)
KatSyntaxError: (use finesse.tb() to see the full traceback)
line 2: unknown element 'l1'. Did you mean 'l'?
1:
-->2: l1 laser P=1
^^
3: pd tmp laser.p1.o
finesse.show_tracebacks() can also switch tracebacks off again:
finesse.show_tracebacks(False)
False