Getting traceback for an error

Since I have seen a lot of posts on the forum struggling with getting the exact traceback for an error (on client side), just wanted to share a strange workaround to make that work

Just add this code to Native Libraries

    function get_error_traceback(err) {
        return err.v.traceback
    }

And then call this function when you get an error (or in your error_handler)

import anvil.js

def fn():
   8/0

try: 
   fn()

except Exception as e:
   print(anvil.js.call("get_error_traceback", e))

This should give an output like this

[
    {"lineno": 10, "colno": 12, "filename": "app/Material_Design_31/Form1/__init__.py"},
    {"lineno": 12, "colno": 12, "filename": "app/Material_Design_31/Form1/__init__.py"},
]

Of course, this is just a hacky workaround which can stop working in future.

5 Likes