Traces back the last formula error.

Returns traceback information if an error is thrown during the last formula execution. Otherwise, returns an empty list. The traceback information is a list of tuples, each of which has 2 or 3 elements depending on show_locals. The first element is a Node object representing a call to a formula. The second element is the line number at which point, the formula either called the next formula or raised the error. When show_locals is True, there exists another elemet. The third element is a dict of the local variables referenced by the formula execution.


show_locals (bool, optional) – Whether to show the local variabls of each call. False by default.


>>> import modelx as mx

>>> @mx.defcells
... def foo(x):
...     a = 1
...     return bar(x) + a

>>> @mx.defcells
... def bar(y):
...     b = 2
...     return 2 * y / 0  # raises ZeroDivisionError

>>> foo(1)
modelx.core.errors.FormulaError: Error raised during formula execution
ZeroDivisionError: division by zero
Formula traceback:
0:, line 3
1:, line 3
Formula source:
def bar(y):
    b = 2
    return 2 * y / 0 #  raise ZeroDivizion

>>> mx.get_traceback(show_locals=True)
[(, 3, {'x': 1, 'a': 1}),
 (, 3, {'y': 1, 'b': 2})]

Changed in version 0.22.0: show_locals option is added.

Changed in version 0.21.0: The 3rd element is added.

See also