pythonbokehholoviewspyvizholoviz

Raise errors and display traceback messages from panel dashboards


When I link widget updates to a function and display the output in a panel, errors that result from updating the widget to a value that the function cannot handle, cause the function to fail silently instead of terminating the execution of the panel and displaying a traceback.

In the following example, x is undefined so when the slider is dragged to 5, the function fails silently and the output value is not updated. If the slider start value is set to 5, the function will raise a NameError as expected and the panel will not be initialized.

import panel as pn

pn.extension()
int_slider = pn.widgets.IntSlider(
    name='Integer Slider', value=1, end=5)

@pn.depends(int_slider.param.value, watch=True)
def print_slider_value(slider_value):
    if slider_value <= 4:
        return slider_value
    else:
        return slider_value * x

pn.Column(int_slider, print_slider_value) #.app('localhost:8888')

I would like errors to be raised when they result from a widget value change, so that it is clear when an error has occured and what happened from the traceback. How can I achieve this with panel? (I saw this issue on debugging mode with pipelines, but couldn't find anything similar for panels).

I have been trying this in the JupyterLab notebook with the following packages versions

bokeh       1.2.0
panel       0.6.0
param       1.9.1
IPython     6.5.0
jupyter_client  5.2.3
jupyter_core    4.4.0
jupyterlab  1.0.2
notebook    5.6.0

Solution

  • Panel v0.14.0 update

    As of version 0.14.0, you can also plug in a simple exception_handler, to show notifications on the client side.

    e.g.

    import logging
    import panel as pn
    
    def exception_handler(ex):
        logging.error("Error", exc_info=ex)
        pn.state.notifications.error('Error: %s' % ex)
    
    pn.extension(exception_handler=exception_handler, notifications=True)
    

    As of version 0.13.0, you can get this functionality out of the box via the Debugging widget.

    e.g.

    logger = logging.getLogger('panel.myapp')
    
    debug_info = pn.widgets.Debugger(
      name='Debugger info level', 
      level=logging.INFO, 
      sizing_mode='stretch_both',
      # comment this line out to get all panel errors
      logger_names=['panel.myapp'] 
    )