File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
jupyter_server/services/kernels Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -323,6 +323,10 @@ def write_stderr(error_message):
323323 channel = getattr (stream , 'channel' , None )
324324 msg_type = msg ['header' ]['msg_type' ]
325325
326+ if channel == 'iopub' and msg_type == 'error' :
327+ self ._on_error (msg )
328+
329+
326330 if channel == 'iopub' and msg_type == 'status' and msg ['content' ].get ('execution_state' ) == 'idle' :
327331 # reset rate limit counter on status=idle,
328332 # to avoid 'Run All' hitting limits prematurely.
@@ -475,6 +479,12 @@ def on_restart_failed(self):
475479 logging .error ("kernel %s restarted failed!" , self .kernel_id )
476480 self ._send_status_message ('dead' )
477481
482+ def _on_error (self , msg ):
483+ if self .kernel_manager .allow_tracebacks :
484+ return
485+ msg ['content' ]['ename' ] = 'ExecutionError'
486+ msg ['content' ]['evalue' ] = 'Execution error'
487+ msg ['content' ]['traceback' ] = [self .kernel_manager .traceback_replacement_message ]
478488
479489#-----------------------------------------------------------------------------
480490# URL to handler mappings
Original file line number Diff line number Diff line change @@ -131,6 +131,18 @@ def __init__(self, **kwargs):
131131 """
132132 )
133133
134+ allow_tracebacks = Bool (True , config = True , help = (
135+ 'Whether to send tracebacks to clients on exceptions.'
136+ ))
137+
138+ traceback_replacement_message = Unicode (
139+ 'An exception occurred at runtime, which is not shown due to security reasons.' ,
140+ config = True ,
141+ help = (
142+ 'Message to print when allow_tracebacks is False, and an exception occurs'
143+ )
144+ )
145+
134146 #-------------------------------------------------------------------------
135147 # Methods for managing kernels and sessions
136148 #-------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments