Skip to content

Commit

Permalink
core: 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 Dec 7, 2015
1 parent f4213ba commit d76b196
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/roby/actions/models/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def run(action_interface, arguments = Hash.new)
raise ArgumentError, "#{name} expects no arguments, but #{arguments.size} are given"
end
result = action_interface.send(name).as_plan
if(!result.class.has_ancestor?(returned_type))

This comment has been minimized.

Copy link
@doudou

doudou Dec 9, 2015

Member

comment on style: don't parenthesis on if(...)

This comment has been minimized.

Copy link
@doudou

doudou Dec 9, 2015

Member

The roby-ish way to test whether a task is of a model is result.fullfills?(returned_type)

This comment has been minimized.

Copy link
@doudou

doudou Dec 9, 2015

Member

it would make more sense to factor the test out of the if/else/end block

raise ArgumentError, "#{name} is expected to return #{returned_type} but returned #{result.class}"
end
else
default_arguments = self.arguments.inject(Hash.new) do |h, arg|
h[arg.name] = arg.default
Expand All @@ -211,6 +214,9 @@ def run(action_interface, arguments = Hash.new)
end
end
result = action_interface.send(name, arguments).as_plan
if(!result.class.has_ancestor?(returned_type))
raise ArgumentError, "#{name} is expected to return #{returned_type} but returned #{result.class}"
end
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 "success condition can no longer be reached '#{relation[:success]}': "
end
explanation.pretty_print(pp)

Expand Down

0 comments on commit d76b196

Please sign in to comment.