Cannot see stack traces

My app is deployed locally, and when there is an error I can’t see the full stack trace. Only a message and one line referencing script_runner. For example:

[chain/error] [1:chain:AgentExecutor] [34.90s] Chain run errored with error:
"HDFKeyNotFoundError('Error message here')"
2024-01-11 18:24:04.314 Uncaught app exception
Traceback (most recent call last):
  File "/Users/me/opt/anaconda3/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/", line 534, in _run_script
    exec(code, module.__dict__)
Error message is here

I have in my .streamlit/config.toml

showErrorDetails = true

Any ideas why the full stack trace isnt showing? Thank you

Hi @my_streamlit_user,

Are you looking in the command line or at the app itself?

Both the command line and the app. The app only shows

  File "/Users/me/opt/anaconda3/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/", line 534, in _run_script
    exec(code, module.__dict__)

Hmmm, interesting. Can you share the full contents of the config.toml file? and a screenshot of the command line if possible?

Sure, the config is:

enableStaticServing = true

showErrorDetails = true

The issue might be with langchain or the interaction of langchain with streamlit.

Seems like this happens as a result of an error in your query to DuckDB (based on this somewhat similar StackOverflow thread) – are there any syntax error in your queries?

Hi Caroline, I figured out the error, but the issue is I cant see any stack traces. Just one line and a short message. I can’t figure out which file or class has the error and the trace to it easily.

Still not seeing stack traces, note the line in streamlit is :

                exec(code, module.__dict__)

This is what chatgpt says so apparently it is expected and should be fixed if chatgpt is correct:

When you use the exec() function in Python to execute dynamically generated Python code, it doesn’t automatically print stack traces for errors that occur within the executed code. If an error happens within the code passed to exec(), the error will stop the execution, but it might not provide a detailed stack trace as you would get from running Python code normally. To capture and print the stack trace from code executed by exec(), you can use the traceback module to catch exceptions and print their stack traces explicitly.

Here is an example of how you can use exec() along with error handling to print the stack trace for errors that occur in dynamically executed Python code:

pythonCopy code

import traceback

code = """
def test_function():
    raise ValueError("An error occurred!")


except Exception as e:

In this example:

  • The exec(code) executes the Python code stored in the code string.
  • If an error occurs during the execution of code, it is caught by the except Exception as e: block.
  • traceback.print_exc() prints the stack trace of the caught exception, providing details about where the error occurred in the dynamically executed code.

This approach allows you to see the stack trace for errors that happen within code run by exec(), making debugging much easier.