lib/eco/api/session/config/workflow.rb in eco-helpers-2.0.41 vs lib/eco/api/session/config/workflow.rb in eco-helpers-2.0.42

- old
+ new

@@ -183,10 +183,11 @@ # @note if a `block` is provided: # - it will **not** run the workflow of the substages to `key` stage # - it will **not** run the `callback` for `on` defined during the configuration time # - it will rather `yield` the target stage after all the `before` _callbacks_ have been run # - aside of this, the rest will be the same as when the _block_ is provided (see previous note) + # @raise [ArgumentError] if the object returned by `before` and `after` callbacks is not an `Eco::API::UseCases::BaseIO`. # @param key [Symbol, nil] cases: # - if `key` is not provided, it targets the _current stage_ # - if `key` is provided, it targets the specific _sub-stage_ # @param io [Eco::API::UseCases::BaseIO] the input/output object # @yield [stage_workflow, io] if a `block` is provided, see `note` @@ -198,11 +199,20 @@ raise "Missing BaseIO object" unless io.is_a?(Eco::API::UseCases::BaseIO) begin if key io = stage(key).run(io: io, &block) elsif pending? - @before.each {|c| io = c.call(self, io)} + @before.each do |c| + io = c.call(self, io).tap do |i_o| + unless i_o.is_a?(Eco::API::UseCases::BaseIO) + msg = "Workflow callaback before('#{name}') should return Eco::API::UseCases::BaseIO object." + msg += " Given #{i_o.class}" + msg += " • Callback source location: '#{c.source_location}'" + raise ArgumentError.new(msg) + end + end + end unless skip? io.session.logger.debug("(Workflow: #{path}) running now") if block io = block.call(self, io) @@ -216,10 +226,19 @@ io = @on.call(self, io) if ready? end @pending = false end - @after.each {|c| io = c.call(self, io)} + @after.each do |c| + io = c.call(self, io).tap do |i_o| + unless i_o.is_a?(Eco::API::UseCases::BaseIO) + msg = "Workflow callaback after('#{name}') should return Eco::API::UseCases::BaseIO object." + msg += " Given #{i_o.class}" + msg += " • Callback source location: '#{c.source_location}'" + raise ArgumentError.new(msg) + end + end + end end rescue SystemExit exit rescue Interrupt => i raise