Workflow Data Exceptions were not getting processed, we now catch the WorkflowDataException through the generic top level SpiffWorkflowException.

This commit is contained in:
Dan 2023-01-26 18:26:17 -05:00
parent b2e44a3ef2
commit 761023c621
3 changed files with 13 additions and 11 deletions

View File

@ -29,8 +29,8 @@ flask-restful = "*"
werkzeug = "*"
# temporarily switch off main to fix CI because poetry export doesn't capture the revision if it's not here (it ignores the lock)
# SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "main"}
SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "450ef3bcd639b6bc1c115fbe35bf3f93946cb0c7"}
# SpiffWorkflow = {develop = true, path = "../SpiffWorkflow" }
# SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "450ef3bcd639b6bc1c115fbe35bf3f93946cb0c7"}
SpiffWorkflow = {develop = true, path = "../SpiffWorkflow" }
sentry-sdk = "^1.10"
sphinx-autoapi = "^2.0"
flask-bpmn = {git = "https://github.com/sartography/flask-bpmn", rev = "main"}

View File

@ -8,6 +8,7 @@ from typing import Any
import flask.wrappers
import sentry_sdk
from SpiffWorkflow.bpmn.exceptions import WorkflowDataException
from flask import Blueprint
from flask import current_app
from flask import g
@ -15,7 +16,7 @@ from flask import jsonify
from flask import make_response
from sentry_sdk import capture_exception
from sentry_sdk import set_tag
from SpiffWorkflow.exceptions import WorkflowException # type: ignore
from SpiffWorkflow.exceptions import WorkflowException, SpiffWorkflowException # type: ignore
from SpiffWorkflow.exceptions import WorkflowTaskException
from SpiffWorkflow.specs.base import TaskSpec # type: ignore
from SpiffWorkflow.task import Task # type: ignore
@ -131,7 +132,7 @@ class ApiError(Exception):
cls,
error_code: str,
message: str,
exp: WorkflowException,
exp: SpiffWorkflowException,
) -> ApiError:
"""Deals with workflow exceptions.
@ -140,6 +141,7 @@ class ApiError(Exception):
we can with the data we have.
"""
if isinstance(exp, WorkflowTaskException):
# Note that WorkflowDataExceptions are also WorkflowTaskExceptions
return ApiError.from_task(
error_code,
message,
@ -150,10 +152,10 @@ class ApiError(Exception):
error_line=exp.error_line,
task_trace=exp.task_trace,
)
else:
elif isinstance(exp, WorkflowException):
return ApiError.from_task_spec(error_code, message, exp.task_spec)
else:
return ApiError("workflow_error", str(exp))
def set_user_sentry_context() -> None:
"""Set_user_sentry_context."""

View File

@ -19,6 +19,7 @@ from typing import TypedDict
from typing import Union
from uuid import UUID
import SpiffWorkflow
import dateparser
import pytz
from flask import current_app
@ -37,7 +38,7 @@ from SpiffWorkflow.bpmn.specs.SubWorkflowTask import SubWorkflowTask # type: ig
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow # type: ignore
from SpiffWorkflow.dmn.parser.BpmnDmnParser import BpmnDmnParser # type: ignore
from SpiffWorkflow.dmn.serializer.task_spec_converters import BusinessRuleTaskConverter # type: ignore
from SpiffWorkflow.exceptions import WorkflowException # type: ignore
from SpiffWorkflow.exceptions import WorkflowException, SpiffWorkflowException # type: ignore
from SpiffWorkflow.exceptions import WorkflowTaskException
from SpiffWorkflow.serializer.exceptions import MissingSpecError # type: ignore
from SpiffWorkflow.spiff.serializer.task_spec_converters import BoundaryEventConverter # type: ignore
@ -1411,9 +1412,8 @@ class ProcessInstanceProcessor:
if hasattr(handler, "bulk_insert_logs"):
handler.bulk_insert_logs() # type: ignore
db.session.commit()
except WorkflowTaskException as we:
raise ApiError.from_workflow_exception("task_error", str(we), we) from we
except SpiffWorkflowException as swe:
raise ApiError.from_workflow_exception("task_error", str(swe), swe) from swe
finally:
if save: