Skip to content

Commit

Permalink
more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tmbo committed Sep 22, 2023
1 parent c183a92 commit 53458a5
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions rasa/shared/core/flows/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

END_STEP = "END"

DEFAULF_STEPS = {END_STEP, START_STEP}
DEFAULT_STEPS = {END_STEP, START_STEP}


class UnreachableFlowStepException(RasaException):
Expand Down Expand Up @@ -65,8 +65,8 @@ def __init__(self, step: FlowStep, flow: Flow) -> None:
def __str__(self) -> Text:
"""Return a string representation of the exception."""
return (
f"Step '{self.step.id}' in flow '{self.flow.id}' is missing a `next` "
f"but is required to have one. "
f"Step '{self.step.id}' in flow '{self.flow.id}' is missing a `next`. "
f"As a last step of a branch, it is required to have one. "
)


Expand All @@ -81,8 +81,8 @@ def __init__(self, step: FlowStep, flow: Flow) -> None:
def __str__(self) -> Text:
"""Return a string representation of the exception."""
return (
f"Step '{self.step.id}' in flow '{self.flow.id}' is using a reserved id. "
f"Please use a different id for your step."
f"Step '{self.step.id}' in flow '{self.flow.id}' is using the reserved id "
f"'{self.step.id}'. Please use a different id for your step."
)


Expand All @@ -98,11 +98,12 @@ def __str__(self) -> Text:
"""Return a string representation of the exception."""
return (
f"Step '{self.step.id}' in flow '{self.flow.id}' is missing an `else` "
f"branch but is required to have one. "
f"branch. If a steps `next` statement contains an `if` it always "
f"also needs an `else` branch. Please add the missing `else` branch."
)


class NoNextAllowedException(RasaException):
class NoNextAllowedForLinkException(RasaException):
"""Raised when a flow step has a next link but is not allowed to have one."""

def __init__(self, step: FlowStep, flow: Flow) -> None:
Expand All @@ -113,8 +114,8 @@ def __init__(self, step: FlowStep, flow: Flow) -> None:
def __str__(self) -> Text:
"""Return a string representation of the exception."""
return (
f"Step '{self.step.id}' in flow '{self.flow.id}' has a `next` but "
f"is not allowed to have one. "
f"Link step '{self.step.id}' in flow '{self.flow.id}' has a `next` but "
f"as a link step is not allowed to have one."
)


Expand Down Expand Up @@ -369,7 +370,7 @@ def validate(self) -> None:
def _validate_not_using_buildin_ids(self) -> None:
"""Validates that the flow does not use any of the build in ids."""
for step in self.steps:
if step.id in DEFAULF_STEPS or step.id.startswith(CONTINUE_STEP_PREFIX):
if step.id in DEFAULT_STEPS or step.id.startswith(CONTINUE_STEP_PREFIX):
raise ReservedFlowStepIdException(step, self)

def _validate_all_branches_have_an_else(self) -> None:
Expand All @@ -389,14 +390,14 @@ def _validate_all_steps_next_property(self) -> None:
if isinstance(step, LinkFlowStep):
# link steps can't have a next link!
if not step.next.no_link_available():
raise NoNextAllowedException(step, self)
raise NoNextAllowedForLinkException(step, self)
elif step.next.no_link_available():
# all other steps should have a next link
raise MissingNextLinkException(step, self)

def _validate_all_next_ids_are_availble_steps(self) -> None:
"""Validates that all next links point to existing steps."""
available_steps = {step.id for step in self.steps} | DEFAULF_STEPS
available_steps = {step.id for step in self.steps} | DEFAULT_STEPS
for step in self.steps:
for link in step.next.links:
if link.target not in available_steps:
Expand Down Expand Up @@ -638,7 +639,7 @@ def _from_json(cls, flow_step_config: Dict[Text, Any]) -> FlowStep:
return FlowStep(
# the idx is set later once the flow is created that contains
# this step
idx=0,
idx=-1,
custom_id=flow_step_config.get("id"),
description=flow_step_config.get("description"),
metadata=flow_step_config.get("metadata", {}),
Expand Down

0 comments on commit 53458a5

Please sign in to comment.