Skip to content

Commit

Permalink
IWF-357: Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lwolczynski committed Jan 6, 2025
1 parent 02ae853 commit 3a40930
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
9 changes: 5 additions & 4 deletions iwf/command_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass
from typing import Any, Union

from iwf.errors import WorkflowDefinitionError
from iwf.errors import WorkflowDefinitionError, NotRegisteredError
from iwf.iwf_api.models import (
ChannelRequestStatus,
CommandResults as IdlCommandResults,
Expand Down Expand Up @@ -59,12 +59,13 @@ def from_idl_command_results(

if not isinstance(idl_results.inter_state_channel_results, Unset):
for inter in idl_results.inter_state_channel_results:
val_type = internal_channel_types.get_type(inter.channel_name)

if val_type is None:
try:
val_type = internal_channel_types.get_type(inter.channel_name)
except NotRegisteredError as exception:
raise WorkflowDefinitionError(
"internal channel is not registered: " + inter.channel_name
)
) from exception

encoded = object_encoder.decode(inter.value, val_type)

Expand Down
10 changes: 5 additions & 5 deletions iwf/communication.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Optional, Union

from iwf.errors import WorkflowDefinitionError
from iwf.errors import WorkflowDefinitionError, NotRegisteredError
from iwf.iwf_api.models import (
EncodedObject,
InterStateChannelPublishing,
Expand Down Expand Up @@ -48,12 +48,12 @@ def trigger_state_execution(self, state: Union[str, type], state_input: Any = No
self._state_movements.append(movement)

def publish_to_internal_channel(self, channel_name: str, value: Any = None):
registered_type = self._internal_channel_type_store.get_type(channel_name)

if registered_type is None:
try:
registered_type = self._internal_channel_type_store.get_type(channel_name)
except NotRegisteredError as exception:
raise WorkflowDefinitionError(
f"InternalChannel channel_name is not defined {channel_name}"
)
) from exception

if (
value is not None
Expand Down
4 changes: 4 additions & 0 deletions iwf/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class InvalidArgumentError(Exception):
pass


class NotRegisteredError(Exception):
pass


class HttpError(RuntimeError):
def __init__(self, status: int, err_resp: ErrorResponse):
super().__init__(err_resp.detail)
Expand Down
6 changes: 3 additions & 3 deletions iwf/type_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum

from iwf.communication_schema import CommunicationMethod
from iwf.errors import WorkflowDefinitionError
from iwf.errors import WorkflowDefinitionError, NotRegisteredError


class Type(Enum):
Expand All @@ -26,11 +26,11 @@ def is_valid_name_or_prefix(self, name: str) -> bool:
t = self._do_get_type(name)
return t is not None

def get_type(self, name: str) -> Optional[type]:
def get_type(self, name: str) -> type:
t = self._do_get_type(name)

if t is None:
raise ValueError(f"{self._class_type} not registered: {name}")
raise NotRegisteredError(f"{self._class_type} not registered: {name}")

return t

Expand Down

0 comments on commit 3a40930

Please sign in to comment.