Skip to content

Commit

Permalink
Stronger typing around galaxy exceptions.
Browse files Browse the repository at this point in the history
Fix err_msg issue.
  • Loading branch information
jmchilton committed Mar 29, 2023
1 parent 1e27fe4 commit 7209c8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions lib/galaxy/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
have nothing to do with the web - keep this in mind when defining exception names
and messages.
"""
from typing import Optional

from .error_codes import (
error_codes_by_name,
Expand All @@ -25,26 +26,27 @@
class MessageException(Exception):
"""Most generic Galaxy exception - indicates merely that some exceptional condition happened."""

err_msg: str
# status code to be set when used with API.
status_code: int = 400
# Error code information embedded into API json responses.
err_code: ErrorCode = error_codes_by_name["UNKNOWN"]

def __init__(self, err_msg=None, type="info", **extra_error_info):
def __init__(self, err_msg: Optional[str] = None, type="info", **extra_error_info):
self.err_msg = err_msg or self.err_code.default_error_message
self.type = type
self.extra_error_info = extra_error_info

@staticmethod
def from_code(status_code, message):
def from_code(status_code: int, message: Optional[str]) -> "MessageException":
exception_class = MessageException
if status_code == 404:
exception_class = ObjectNotFound
elif status_code / 100 == 5:
exception_class = InternalServerError
return exception_class(message)

def __str__(self):
def __str__(self) -> str:
return self.err_msg


Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy/workflow/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -2514,9 +2514,9 @@ def populate_module_and_state(
if step_errors:
raise exceptions.MessageException(step_errors, err_data={step.order_index: step_errors})
if step.upgrade_messages:
upgrade_messages = step.upgrade_messages
error_message = f'Workflow step "{step.id}" had upgrade messages: {upgrade_messages}'
if allow_tool_state_corrections:
log.debug('Workflow step "%i" had upgrade messages: %s', step.id, step.upgrade_messages)
log.debug(error_message)
else:
raise exceptions.MessageException(
step.upgrade_messages, err_data={step.order_index: step.upgrade_messages}
)
raise exceptions.MessageException(error_message, err_data={step.order_index: upgrade_messages})

0 comments on commit 7209c8d

Please sign in to comment.