Skip to content

Hide the Traceback stack trace in the browser for errors during app initialization #8647

Description

@dataF0g

Hi everyone,

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!

Versions:

bokeh==3.8.2
panel==1.8.10

Discourse discussion: https://discourse.holoviz.org/t/how-to-hide-the-traceback-stack-trace-in-the-browser-for-errors-during-app-initialization/9262/1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions