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

Normalize functions to all take arguments #238

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

Fryguy
Copy link
Member

@Fryguy Fryguy commented Jul 2, 2024

With all functions able to take parameters, then we can do argument checking in the transformer. This commit adds argument checking for States.UUID.

@agrare Please review.

This allows for the separation of syntax errors from semantic errors.

I did this PR separate as a precursor to States.ArrayPartition where I actually have to check arity and specific argument types. States.UUID shows how that can be achieved.

Not sure if we want to raise ArgumentError or something else? Thoughts?

@Fryguy Fryguy requested a review from agrare as a code owner July 2, 2024 21:00
@Fryguy Fryguy added the enhancement New feature or request label Jul 2, 2024
With all functions able to take parameters, then we can do argument
checking in the transformer. This commit adds argument checking for
States.UUID.
@Fryguy Fryguy force-pushed the normalize_function_calls branch from 47c24cb to 21f1dac Compare July 2, 2024 21:02
@miq-bot
Copy link
Member

miq-bot commented Jul 2, 2024

Checked commit Fryguy@21f1dac with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
4 files checked, 0 offenses detected
Everything looks fine. 🍰

@Fryguy Fryguy mentioned this pull request Jul 2, 2024
@agrare
Copy link
Member

agrare commented Jul 2, 2024

I think passing arguments to a function that doesn't take one is a payload problem not a runtime problem (like an argument being a string instead of an int or something) so InvalidWorkfloeError would make sense

@Fryguy
Copy link
Member Author

Fryguy commented Jul 2, 2024

@agrare Maybe? If it's hardcoded I would agree, but if it's inferred, it's a runtime problem I think.

Compare States.ArrayContains(States.Array(1, 2, 3), -1) vs States.ArrayContains($.input, $.target) with an input of {:input => [1, 2, 3], :target => -1}. The latter is a runtime error I would think not a workflow error.

@kbrock
Copy link
Member

kbrock commented Jul 3, 2024

I've found it is hard to guess when aws will throw a runtime exception and when they will not. In some cases, doing a StringEquals doesn't throw an exception when a StringGreaterThan will. (where the arguments are a string and an integer) -- you can see a few examples in that fixtures file I had.

I think using guard clauses (via Choice) and checking types is the only way around these nuances.

@Fryguy
Copy link
Member Author

Fryguy commented Jul 3, 2024

I wasnt trying to follow aws here, but maybe that's a good idea to see what the simulator does

@Fryguy
Copy link
Member Author

Fryguy commented Jul 3, 2024

@agrare if it's ok, can we merge for now with the regular ArgumentError? Reason is I'm starting to do others and patterns are emerging. I think it's clearer what choices to make with more examples. I'm also seeing that I can normalize most of the arity and type checks.

@agrare
Copy link
Member

agrare commented Jul 3, 2024

Compare States.ArrayContains(States.Array(1, 2, 3), -1) vs States.ArrayContains($.input, $.target) with an input of {:input => [1, 2, 3], :target => -1}. The latter is a runtime error I would think not a workflow error.

I was thinking more along the lines of if someone wrote States.UUID(1) that for sure is a definition error not a runtime error


rule(:states_uuid => {:args => subtree(:args)}) do
args = Transformer.resolve_args(args())
raise ArgumentError, "wrong number of arguments to States.UUID (given #{args.size}, expected 0)" unless args.empty?
Copy link
Member

Choose a reason for hiding this comment

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

I do think this should be Floe::InvalidWorkflowError instead of ArgumentError, or maybe we catch ArgumentError while evaluating the intrinsic_function and raise InvalidWorkflowError then?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I'm seeing patterns where I check arity (which I agree is a workflow error), then types (which feels more like a runtime error), and then specific conditions like argument must be non-zero positive (which also feels like a runtime error)

I agree 100% that all of those errors we should wrap, and will do in a follow up

Copy link
Member

Choose a reason for hiding this comment

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

I check arity (which I agree is a workflow error), then types (which feels more like a runtime error), and then specific conditions like argument must be non-zero positive (which also feels like a runtime error)

Completely agree on these

Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

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

I think we should tweak what exceptions we're raising so we aren't exposing "ruby" internals to the end user but can do that in a follow-up

@agrare agrare merged commit cfe11b7 into ManageIQ:master Jul 3, 2024
5 checks passed
@Fryguy Fryguy deleted the normalize_function_calls branch July 3, 2024 15:36
agrare added a commit that referenced this pull request Aug 1, 2024
Added
- Set Floe.logger.level if DEBUG env var set (#234)
- Add InstrinsicFunction foundation + States.Array, States.UUID (#194)
- Evaluate IntrinsicFunctions from PayloadTemplate (#236)
- Add more intrinsic functions (#242)
- Add State#cause_path, error_path (#249)
- Validate Catcher Next (#250)
- Add spec/supports (#248)

Fixed
- Handle non-hash input/output values (#214)
- Fix Input/Output handling for Pass, Choice, Succeed states (#225)
- Wrap Parslet::ParseFailed errors as Floe::InvalidWorkflowError (#235)
- Fix edge cases with States.Array (#237)
- Fix sporadic test failure with Wait state (#243)
- Fix invalid container names after normalizing (#252)

Changed
- Extract ErrorMatcherMixin from Catch and Retry (#186)
- Output should be JSON (#230)
- Normalize functions to all take arguments (#238)
- Pass full path name to State.new for better errors (#229)
- Validate that state machine input is valid JSON (#227)
- Move the Parslet parse into initialize so that invalid function definition will fail on workflow load (#245)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants