class Roby::Queries::ExecutionExceptionMatcher
Object
that allows to specify generalized matches on a Roby::ExecutionException
object
Attributes
An object that will be used to match the actual (Ruby) exception @return [LocalizedErrorMatcher]
An object that will be used to match the exception origin @return [Array<#===,TaskMatcher>]
Public Class Methods
# File lib/roby/queries/execution_exception_matcher.rb, line 13 def initialize @exception_matcher = LocalizedErrorMatcher.new @involved_tasks_matchers = Array.new @expected_edges = nil @handled = nil end
Public Instance Methods
@return [Boolean] true if the given execution exception object
matches self, false otherwise
# File lib/roby/queries/execution_exception_matcher.rb, line 136 def ===(exception) if !exception.respond_to?(:to_execution_exception) return false end exception = exception.to_execution_exception exception_matcher === exception.exception && involved_tasks_matchers.all? { |m| exception.trace.any? { |t| m === t } } && (!@expected_edges || (@expected_edges == exception.trace.each_edge.to_set)) && (@handled.nil? || !(@handled ^ exception.handled?)) end
# File lib/roby/queries/execution_exception_matcher.rb, line 147 def describe_failed_match(exception) if !(exception_matcher === exception.exception) return exception_matcher.describe_failed_match(exception.exception) elsif missing_involved_task = involved_tasks_matchers.find { |m| exception.trace.none? { |t| m === t } } return "#{missing_involved_task} cannot be found in the exception trace\n #{exception.trace.map(&:to_s).join("\n ")}" end end
(see LocalizedErrorMatcher#fatal)
# File lib/roby/queries/execution_exception_matcher.rb, line 48 def fatal exception_matcher.fatal self end
# File lib/roby/queries/execution_exception_matcher.rb, line 20 def handled(flag = true) @handled = flag self end
Matched exceptions must have a task in their trace that matches the given task matcher
@param [TaskMatcher] task_matcher
# File lib/roby/queries/execution_exception_matcher.rb, line 92 def involving(task_matcher) involved_tasks_matchers << origin_matcher self end
# File lib/roby/queries/execution_exception_matcher.rb, line 155 def matches_task?(task) involved_tasks_matchers.all? { |m| m === task } && exception_matcher.matches_task?(task) end
# File lib/roby/queries/execution_exception_matcher.rb, line 25 def not_handled handled(false) end
# File lib/roby/queries/execution_exception_matcher.rb, line 101 def pretty_print(pp) pp.text "ExecutionException(" exception_matcher.pretty_print(pp) pp.text ")" if !involved_tasks_matchers.empty? pp.text ".involving(" pp.nest(2) do involved_tasks_matchers.each do |m| pp.breakable m.pretty_print(pp) end end pp.text ")" end if @expected_edges pp.text ".with_trace(" pp.nest(2) do @expected_edges.each do |a, b, _| pp.breakable pp.text "#{a} => #{b}" end end pp.text ")" end if !@handled.nil? if @handled pp.text ".handled" else pp.text ".not_handled" end end end
# File lib/roby/queries/execution_exception_matcher.rb, line 160 def to_execution_exception_matcher self end
# File lib/roby/queries/execution_exception_matcher.rb, line 97 def to_s PP.pp(self, "") end
# File lib/roby/queries/execution_exception_matcher.rb, line 53 def with_empty_trace @expected_edges = Set.new self end
Sets the exception matcher object
# File lib/roby/queries/execution_exception_matcher.rb, line 30 def with_exception(exception_matcher) @exception_matcher = exception_matcher self end
(see LocalizedErrorMatcher#with_model
)
# File lib/roby/queries/execution_exception_matcher.rb, line 36 def with_model(exception_model) exception_matcher.with_model(exception_model) self end
(see LocalizedErrorMatcher#with_origin
)
# File lib/roby/queries/execution_exception_matcher.rb, line 42 def with_origin(plan_object_matcher) exception_matcher.with_origin(plan_object_matcher) self end
Match the exception trace
The trace is a representation of the exception's propagation during Roby's exception propagation phase. This verifies that the graph contains the edges specified by its argument
@overload with_trace
(*edges)
@param [Array<Task>] edges specify the edges of the propagation graph two-by-two, source then sink @example match a graph with (source0, sink0), (source0, sink1) edges with_trace(source0, sink0, source0, sink1)
@overload with_trace
(edges)
@param [Hash] edges specify edges as a mapping. Edges that share the same source must be specified as source=>[sink0, sink1] @example match a graph with (source0, sink0), (source0, sink1) edges with_trace(source0 => [sink0, sink1])
# File lib/roby/queries/execution_exception_matcher.rb, line 78 def with_trace(*edges) if edges.first.kind_of?(Hash) edges = edges.first.to_a.flat_map do |source, targets| Array(targets).flat_map { |t| [source, t] } end end @expected_edges = edges.each_slice(2).map { |a, b| [a, b, nil] }.to_set self end