Skip to content

Commit

Permalink
Action: improve error message in case of wrong return types
Browse files Browse the repository at this point in the history
at the moment the follwoing code produces an error which is not
really addressing the issue

Robot.actions do
    describe('move robot')
    def move(arg)
        Roby::Task.new
    end
end
--> invalid replacement: missing provided models
Roby2::Actions::Main::Move
  • Loading branch information
Alexander Duda authored and Alexander Duda committed Nov 10, 2015
1 parent b68f70c commit 651007c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/roby/actions/models/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ def run(action_interface, arguments = Hash.new)
if !arguments.empty?
raise ArgumentError, "#{name} expects no arguments, but #{arguments.size} are given"
end
result = action_interface.send(name).as_plan
result = action_interface.send(name)
if(!result.class.has_ancestor?(returned_type))
raise ArgumentError, "#{name} is expected to return #{returned_type} but returned #{result.class}"
end
result = result.as_plan
else
default_arguments = self.arguments.inject(Hash.new) do |h, arg|
h[arg.name] = arg.default
Expand All @@ -210,7 +214,11 @@ def run(action_interface, arguments = Hash.new)
raise ArgumentError, "required argument #{arg.name} not given to #{name}"
end
end
result = action_interface.send(name, arguments).as_plan
result = action_interface.send(name, arguments)
if(!result.class.has_ancestor?(returned_type))
raise ArgumentError, "#{name} is expected to return #{returned_type} but returned #{result.class}"
end
result = result.as_plan
end
# Make the planning task inherit the model/argument flags
if planning_task = result.planning_task
Expand Down
2 changes: 1 addition & 1 deletion lib/roby/relations/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ def pretty_print(pp) # :nodoc:
if mode == :failed_event
pp.text "triggered the failure predicate '#{relation[:failure]}': "
elsif mode == :unreachable_success
pp.text "cannot reach the success condition '#{relation[:success]}': "
pp.text "child terminated, success condition can no longer be reached '#{relation[:success]}': "
end
explanation.pretty_print(pp)

Expand Down

0 comments on commit 651007c

Please sign in to comment.