Skip to content

Commit

Permalink
Merge pull request #14 from openimis/enhancement/pythonHandlerError
Browse files Browse the repository at this point in the history
Added exception for python worflow handler
  • Loading branch information
malinowskikam committed Feb 16, 2024
2 parents 66b91fe + abaf9ee commit abf35c6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions workflow/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

class PythonWorkflowHandlerException(Exception):
"""
Custom exception class for handling errors within Python Workflows.
"""

def __init__(self, message, *args, **kwargs):
if args or kwargs:
message = message.format(*args, **kwargs)
super().__init__(message)
self.message = message

def __str__(self):
"""
Return the string representation of the exception.
"""
return f"PythonWorkflowHandlerException: {self.message}"
9 changes: 9 additions & 0 deletions workflow/systems/python/handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from typing import Dict

from workflow.exceptions import PythonWorkflowHandlerException
from workflow.systems.base import WorkflowHandler
from workflow.util import result

Expand All @@ -19,6 +20,14 @@ def run(self, data: Dict):
success=True,
data=output
)
# Dedicated exception handling for workflow exceptions that should have custom message
except PythonWorkflowHandlerException as e:
logging.error("Error while executing workflow %s-%s: ", self.system, self.name, exc_info=e)
return result(
success=False,
message=e.message,
details=str(e)
)
except Exception as e:
logging.error("Error while executing workflow %s-%s: ", self.system, self.name, exc_info=e)
return result(
Expand Down

0 comments on commit abf35c6

Please sign in to comment.