Skip to content

Commit f330347

Browse files
kevin-bateslresende
authored andcommitted
Flow custom error messages to client.
This PR also requires [Kernel Gateway PR 284](jupyter-server/kernel_gateway#284) In absence of that PR, the default message corresponding to the status code will be returned to the caller. This PR is essentially preparation to have custom error messages returned. Fixes #296 Closes #310
1 parent 76923a7 commit f330347

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

enterprise_gateway/services/processproxies/conductor.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ def launch_process(self, kernel_cmd, **kw):
4747
if env_dict and 'EGO_SERVICE_CREDENTIAL' in env_dict:
4848
self.rest_credential = env_dict['EGO_SERVICE_CREDENTIAL']
4949
else:
50-
self.log.error("ConductorClusterProcessProxy failed to obtain the Conductor credential.")
51-
raise tornado.web.HTTPError(500, "ConductorClusterProcessProxy failed to obtain the Conductor credential.")
50+
error_message = "ConductorClusterProcessProxy failed to obtain the Conductor credential."
51+
self.log.error(error_message)
52+
raise tornado.web.HTTPError(500, reason=error_message)
53+
5254
# dynamically update Spark submit parameters
5355
self.update_launch_info(kernel_cmd, **kw)
5456
# Enable stderr PIPE for the run command
@@ -197,10 +199,11 @@ def confirm_remote_startup(self, kernel_cmd, **kw):
197199
app_state = self.get_application_state()
198200

199201
if app_state in ConductorClusterProcessProxy.final_states:
200-
raise tornado.web.HTTPError(500, "KernelID: '{}', ApplicationID: '{}' unexpectedly found in"
201-
"state '{}' during kernel startup!".format(self.kernel_id,
202-
self.application_id,
203-
app_state))
202+
error_message = "KernelID: '{}', ApplicationID: '{}' unexpectedly found in " \
203+
"state '{}' during kernel startup!".\
204+
format(self.kernel_id, self.application_id, app_state)
205+
self.log.error(error_message)
206+
raise tornado.web.HTTPError(500, reason=error_message)
204207

205208
self.log.debug("{}: State: '{}', Host: '{}', KernelID: '{}', ApplicationID: '{}'".
206209
format(i, app_state, self.assigned_host, self.kernel_id, self.application_id))
@@ -243,7 +246,7 @@ def handle_timeout(self):
243246
self.kill()
244247
timeout_message = "KernelID: '{}' launch timeout due to: {}".format(self.kernel_id, reason)
245248
self.log.error(timeout_message)
246-
raise tornado.web.HTTPError(error_http_code, timeout_message)
249+
raise tornado.web.HTTPError(error_http_code, reason=timeout_message)
247250

248251
def get_application_id(self, ignore_final_states=False):
249252
# Return the kernel's application ID if available, otherwise None. If we're obtaining application_id
@@ -380,7 +383,7 @@ def kill_app_by_driver_id(self, driver_id):
380383
if self.application_id is None:
381384
return None
382385
self.log.debug("Driver does not exist, retrieving DriverID with ApplicationID: {}".format(self.application_id))
383-
driver_info = get_driver_by_app_id(self.application_id)
386+
driver_info = self.get_driver_by_app_id(self.application_id)
384387
if driver_info:
385388
self.driver_id = driver_info['id']
386389
else:

enterprise_gateway/services/processproxies/distributed.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,4 @@ def handle_timeout(self):
121121
timeout_message = "KernelID: '{}' launch timeout due to: {}".format(self.kernel_id, reason)
122122
self.log.error(timeout_message)
123123
self.kill()
124-
raise tornado.web.HTTPError(error_http_code, timeout_message)
124+
raise tornado.web.HTTPError(error_http_code, reason=timeout_message)

enterprise_gateway/services/processproxies/processproxy.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def _get_ssh_client(self, host):
239239
if e is paramiko.SSHException or paramiko.AuthenticationException:
240240
error_message_prefix = "Failed to authenticate SSHClient with password"
241241
error_message = error_message_prefix + (" provided" if remote_pwd else "-less SSH")
242-
raise tornado.web.HTTPError(403, error_message)
242+
raise tornado.web.HTTPError(403, reason=error_message)
243243
else:
244244
raise e
245245
return ssh
@@ -352,7 +352,7 @@ def _raise_authorization_error(self, kernel_username, differentiator_clause):
352352
"Ensure KERNEL_USERNAME is set to an appropriate value and retry the request.". \
353353
format(kernel_username, differentiator_clause, kernel_clause)
354354
self.log.error(error_message)
355-
raise tornado.web.HTTPError(403, error_message)
355+
raise tornado.web.HTTPError(403, reason=error_message)
356356

357357
def _enforce_limits(self, **kw):
358358
"""
@@ -685,9 +685,10 @@ def receive_connection_info(self):
685685
if conn:
686686
conn.close()
687687
else:
688-
raise tornado.web.HTTPError(500,
689-
"Unexpected runtime found for KernelID '{}'! "
690-
"No response socket exists".format(self.kernel_id))
688+
error_message = "Unexpected runtime found for Kernel ID '{}'! No response socket exists".format(self.kernel_id)
689+
self.log.error(error_message)
690+
raise tornado.web.HTTPError(500, reason=error_message)
691+
691692
return ready_to_connect
692693

693694
# Do NOT update connect_info with IP and other such artifacts in this method/function.

enterprise_gateway/services/processproxies/yarn.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ def confirm_remote_startup(self, kernel_cmd, **kw):
154154
app_state = self.get_application_state()
155155

156156
if app_state in YarnClusterProcessProxy.final_states:
157-
raise tornado.web.HTTPError(500, "KernelID: '{}', ApplicationID: '{}' unexpectedly found in"
158-
"state '{}' during kernel startup!".format(self.kernel_id,
159-
self.application_id,
160-
app_state))
157+
error_message = "KernelID: '{}', ApplicationID: '{}' unexpectedly found in " \
158+
"state '{}' during kernel startup!".\
159+
format(self.kernel_id, self.application_id, app_state)
160+
self.log.error(error_message)
161+
raise tornado.web.HTTPError(500, reason=error_message)
161162

162163
self.log.debug("{}: State: '{}', Host: '{}', KernelID: '{}', ApplicationID: '{}'".
163164
format(i, app_state, self.assigned_host, self.kernel_id, self.application_id))
@@ -199,7 +200,7 @@ def handle_timeout(self):
199200
self.kill()
200201
timeout_message = "KernelID: '{}' launch timeout due to: {}".format(self.kernel_id, reason)
201202
self.log.error(timeout_message)
202-
raise tornado.web.HTTPError(error_http_code, timeout_message)
203+
raise tornado.web.HTTPError(error_http_code, reason=timeout_message)
203204

204205
def get_application_id(self, ignore_final_states=False):
205206
# Return the kernel's YARN application ID if available, otherwise None. If we're obtaining application_id

0 commit comments

Comments
 (0)