ManageIQ / floe

Floe is a runner for Amazon States Language workflows
Apache License 2.0
0 stars 5 forks source link

[WIP] [POS] Common Error message dsl #232

Closed kbrock closed 2 months ago

kbrock commented 2 months ago

Yet another alternative to #209

Built up #209 as 2 concepts: increase the error checking and add a dsl Kinda overkill, but it is nice having all the validations in one place.

If we want to go forward, I can squash and make it work better with ChoiceRule::Data.

Master

class Pass
  attr_reader :end, :next, :result, :parameters, :input_path, :output_path, :result_path

  def initialize(workflow, name, payload)
    super

    @next        = payload["Next"]
    @end         = !!payload["End"]
    @result      = payload["Result"]

    @parameters  = payload_template!("Parameters", payload["Parameters"])
    @input_path  = path!("InputPath", payload.fetch("InputPath", "$"))
    @output_path = path!("OutputPath", payload.fetch("OutputPath", "$"))
    @result_path = reference_path!("ResultPath", payload.fetch("ResultPath", "$"))

    validate_state!(workflow)
  end

  def validate_state!(workflow)
    validate_state_next!(workflow)
  end
end

209+

First half of this PR validates every field:

class Pass
  attr_reader :end, :next, :result, :parameters, :input_path, :output_path, :result_path

  def initialize(workflow, name, payload)
    super

    @next        = state_ref!("Next", payload["Next"], workflow)
    @end         = boolean!("End", payload["End"])
    @result      = payload["Result"]

    @parameters  = payload_template!("Parameters", payload["Parameters"])
    @input_path  = path!("InputPath", payload.fetch("InputPath", "$"))
    @output_path = path!("OutputPath", payload.fetch("OutputPath", "$"))
    @result_path = reference_path!("ResultPath", payload.fetch("ResultPath", "$"))

    require_field!(%w[Next End], [@next, @end])
  end
end

After

Second half adds a DSL

class Pass
  fields do
    state_ref        "Next"
    boolean          "End"
    raw              "Result"
    payload_template "Parameters"
    path             "InputPath",  default: "$"
    path             "OutputPath", default: "$"
    reference_path   "ResultPath", default: "$"

    # we require either the next or the end field
    requires "Next", "End"
  end
end
miq-bot commented 2 months ago

Checked commits https://github.com/kbrock/floe/compare/89b36a08d9447c498fe7458c9a968564f339c89d~...78ac3ff9fdd4377b86ff8e29fd515a24f3e93785 with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint 23 files checked, 0 offenses detected Everything looks fine. :star:

miq-bot commented 2 months ago

This pull request is not mergeable. Please rebase and repush.

kbrock commented 2 months ago

WIP: neat experiment, going to extract some ideas and then delete

kbrock commented 2 months ago

This improves error messages. Those changes have made their way into #229 This tests every parameter. Merging this branch into #209 to preserve that work.

As for the DSL, may leave that in 209 or may toss. It is here if anyone wants to enjoy