I have a multipage app here that has multiple users in their own session. They sometimes encounter logic errors that get displayed on screen and stop the app.
I know how to write securely to a database that I host on Render.
My question is does anyone know how to extract the error message so that I can write it to the database against the user’s session?
Example below:
TypeError: 'NoneType' object is not subscriptable
Traceback:
<the trace back errors>
What you suggested could be what I’m looking for, and naturally I am familiar with try except blocks. Never though to do it so “globally” on a page though!
Referring to this documentation, would that mean effectively wrapping my entire page in a try …except (RuntimeError, TypeError, NameError) block so that if anything fails on that page, it results in an exception?
Well, I am not sure what the scope of your question is. AFAIK you can extract the error message only from the exception, and you can have the exception only if you catch it. So if you want to log messages raised by every line of code, you need every line of code wrapped.
Note that exception handling in the main script won’t catch exceptions raised in callbacks, you have to handle them separately.
Hi @Goyo I guess I am looking for a more “universal” solution so that if there is any logic error that occurs in a page that ends up emitting an error message and stops the app from running, I would like to capture it and store it in a database.
If the only way to do that is to wrap every line of code then that won’t be a practical solution.
If I could wrap the entire page then I guess that would be preferable but it doesn’t sound like that’s possible anyway.
Thanks for the suggestion.
How is this issue dealt with in practice? Surely this is a common scenario.
That is indeed possible, but not enough: you might need to wrap the callbacks too.
Note that this is not streamlit-specific. Logging exceptions is just one instance of handling exceptions, and exception handling in python means try ... except.
Even streamlit itself must be doing something like this, it needs to catch the exceptions in order to sent the error messages to the browser.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.