Hi everyone,
I’m working with a Panel application where I’ve noticed that if an error occurs during the initialization of a component, the full Traceback is displayed directly in the browser.
While this is helpful for debugging, I’d like to avoid showing the internal stack trace and sensitive path information to end-users in a production-like environment.
Here is a minimal reproducible example:
import panel as pn
import param
class ErrorExample(pn.viewable.Viewer):
param_a = param.String(default="Example")
def __init__(self, **params):
super().__init__(**params)
raise RuntimeError("An error occurred during initialization")
def __panel__(self):
return pn.Column(f"# {self.param_a}")
def get_app():
return ErrorExample()
if __name__ == "__main__":
pn.serve(get_app)
Currently, when I run this and open the browser, I see:
RuntimeError
Traceback (most recent call last):
File ".../panel/io/handlers.py", line 366, in run_app
handler._func(doc)
File ".../panel/io/application.py", line 75, in _eval_panel
panel = panel()
^^^^^^^
File "error_example.py", line 18, in get_app
return ErrorExample()
^^^^^^^^^^^^^^
File "error_example.py", line 11, in __init__
raise RuntimeError("An error occurred during initialization")
RuntimeError: An error occurred during initialization
Question:
Is there a built-in Panel or Bokeh configuration (or a recommended pattern) to suppress this traceback in the UI and perhaps show a custom “Internal Server Error” message instead, while still logging the full error to the server console?
Thanks in advance for any help!
