Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Abort if StartAt or Next [state] is not valid #125

Closed
wants to merge 1 commit into from

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Oct 6, 2023

I tried to run a workflow with an invalid StartAt
This caused a strange error

before

lib/floe/workflow.rb:76:in `step_nonblock': undefined method `run_nonblock!' for nil:NilClass (NoMethodError)

      current_state.run_nonblock!
                   ^^^^^^^^^^^^^^
	from lib/floe/workflow.rb:63:in `step'
	from lib/floe/workflow.rb:58:in `run!'
	from exe/floe:37:in `<top (required)>'

after

{"Error"=>"States.Runtime", "Cause"=>"State \"FirstState\" does not exist"}

I was running a workflow with an invalid StartAt
This caused a strange error

before
------

```
lib/floe/workflow.rb:76:in `step_nonblock': undefined method `run_nonblock!' for nil:NilClass (NoMethodError)

      current_state.run_nonblock!
                   ^^^^^^^^^^^^^^
	from lib/floe/workflow.rb:63:in `step'
	from lib/floe/workflow.rb:58:in `run!'
	from exe/floe:37:in `<top (required)>'
```

after
-----

```
{"Error"=>"States.Runtime", "Cause"=>"State \"FirstState\" does not exist"}
```
@kbrock kbrock added the bug Something isn't working label Oct 6, 2023
@kbrock kbrock changed the title Abort if StartAt or next_state is not valid Abort if StartAt or Next [state] is not valid Oct 6, 2023
@agrare
Copy link
Member

agrare commented Oct 6, 2023

@kbrock this seems like something we should catch at load time, at least StartAt and static Next states (maybe even validate all choice state targets are valid states)

@kbrock kbrock changed the title Abort if StartAt or Next [state] is not valid [WIP] Abort if StartAt or Next [state] is not valid Oct 6, 2023
@kbrock kbrock added the wip label Oct 6, 2023
@kbrock
Copy link
Member Author

kbrock commented Oct 6, 2023

keep the spec.
WIP: make this a payload parsing check

@miq-bot
Copy link
Member

miq-bot commented Oct 6, 2023

Checked commits kbrock/floe@1eb25f2~...6cdcf85 with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint
4 files checked, 0 offenses detected
Everything looks fine. 🍰

@kbrock
Copy link
Member Author

kbrock commented Oct 10, 2023

TODO: rail at load time rather than catching this exception.

I still feel we need better runtime failures, but agree this error in particular needs to happen at load/validation time

@kbrock
Copy link
Member Author

kbrock commented Oct 10, 2023

If we add validation on NextState, something like #106 would be nice.

context.state = {"Name" => context.next_state, "Input" => context.output} if context.next_state
desired_state = context.next_state || context.state_name
if !@states_by_name.key?(desired_state)
context.state["Error"] = "States.Runtime"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually a runtime error? It seems like more of a workflow definition error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a task/issue somewhere to validate workflows before we run them and raise exceptions early. I'm wondering if now is the time to add in that logic, and then have a separate Workflow#validate or Workflow#valid? method with this as the first thing we check for. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP: make this a payload parsing check

That's maybe similar to what I'm saying, but it's not a parse failure and more of a logical validation failure. I think of parsing failures more of like being bad syntax. Perhaps I'm over-engineering though?

@kbrock
Copy link
Member Author

kbrock commented Oct 11, 2023

Going with validation instead: #130

@kbrock kbrock closed this Oct 11, 2023
@kbrock kbrock deleted the check_state_name branch October 11, 2023 20:24
@agrare
Copy link
Member

agrare commented Oct 30, 2023

Hey @kbrock let me know what you think about #136 and if that covers the concerns you had with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wip
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants