How do I show the content of the call stack on the client?

The short version:
How do I show the content of the call stack on the client?

Some context:
Sometimes a function is executed and I don’t know why.

Importing traceback on the client side doesn’t work:

NotImplementedImportError: traceback is not yet implemented in Skulpt

A trick that allows me to see what called that function is to add something like print(1/0), so I can see the stack and understand what called that function.

The problem with this trick (beside being pretty ugly) is that it can’t be used if there is some catch all try-except (which shouldn’t be used, but, you know…)

I tried calling this, but it only shows the server side stack, nothing from the client side:

@anvil.server.callable
def show_traceback():
    import traceback
    print('\n'.join(str(i) for i in traceback.extract_stack()))

Skulpt is able to show the stack, because it does show it when there is an error.

1 Like

I’d asked that before, and the response was that Skulpt didn’t expose that to Python yet. Since that time ExternalErrors have gotten a bit of extra info to access the Javascript exceptions: Anvil Docs | Accessing Javascript

There’s also a workaround for getting the current line number out of Skulpt: Skulpt limitations on SyntaxError? - #4 by divyeshlakhotia

All of that’s only with exceptions, though.

2 Likes

That helps a little, but I would like to see the full stack.

If I see a function that is called 10 times when I click a button, I want to know what triggered each call.

I would like to add a show_traceback() at the beginning of the function, so I know the cause of the 10 calls.

2 Likes

Definitely agreed! It sounds like traceback support in Skulpt is on the list, but farther down than other features. As you say, the information is there, it’s just exposing it to Python.

1 Like