How to hide the Traceback stack trace in the browser for errors during app initialization?

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!

1 Like

Are you able to switch pn.serve to .servable()?

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}")


ErrorExample().servable()
 panel serve test.py
2026-06-17 10:01:21,210 Starting Bokeh server version 3.9.0 (running on Tornado 6.5.5)
2026-06-17 10:01:21,211 User authentication hooks NOT provided (default user enabled)
2026-06-17 10:01:21,212 Bokeh app running at: http://localhost:5006/test
2026-06-17 10:01:21,213 Starting Bokeh server with process id: 55152
2026-06-17 10:01:22,590 Error running application handler ...

RuntimeError: An error occurred during initialization

It would then show:

You can also try/except and return an error screen, albeit a bit hacky:

import panel as pn
import param


class ErrorExample(pn.viewable.Viewer):
    param_a = param.String(default="Example")

    def __init__(self, **params):
        super().__init__(**params)
        try:
            raise RuntimeError("An error occurred during initialization")
        except:
            # redefine panel
            self.__panel__ = lambda: "Error"

    def __panel__(self):
        return pn.Column(f"# {self.param_a}")


ErrorExample().servable()
1 Like

However, I think this is a good GitHub issue to have.

Thanks @ahuang11 and done: Hide the Traceback stack trace in the browser for errors during app initialization · Issue #8647 · holoviz/panel · GitHub