class Roby::Queries::LocalizedErrorMatcher

Object that allows to specify generalized matches on a Roby::LocalizedError object

Attributes

failure_point_matcher[R]

@return [#===] the object that will be used to match the error

origin
model[R]

@return [Class] the exception class that should be matched. It

must be a subclass of LocalizedError, and is LocalizedError by
default
original_exception_model[R]

@return [#===,nil] match object to validate the exception's

ExeptionBase#original_exceptions

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/roby/queries/localized_error_matcher.rb, line 17
def initialize
    super
    @model = LocalizedError
    @failure_point_matcher = Queries.any
    @original_exception_model = nil
end

Public Instance Methods

===(exception) click to toggle source

@return [Boolean] true if the given execution exception object

matches self, false otherwise
# File lib/roby/queries/localized_error_matcher.rb, line 61
def ===(exception)
    if !(model === exception)
        return false
    end

    if original_exception_model
        original_exception = exception.original_exceptions.
            find { |e| original_exception_model === e }
        if !original_exception
            return false
        end
    end

    if !exception.failed_task
        if !(failure_point_matcher === exception.failed_generator)
            return false
        end
    elsif failure_point_matcher.respond_to?(:task_matcher)
        if exception.failed_generator
            return false if !(failure_point_matcher === exception.failed_generator)
        else return false
        end
    else
        return false if !(failure_point_matcher === exception.failed_task)
    end

    original_exception || true
end
describe_failed_match(exception) click to toggle source
# File lib/roby/queries/localized_error_matcher.rb, line 90
def describe_failed_match(exception)
    if !(model === exception)
        return "exception model #{exception} does not match #{model}"
    end

    if original_exception_model
        original_exception = exception.original_exceptions.
            find { |e| original_exception_model === e }
        if !original_exception
            if exception.original_exceptions.empty?
                return "expected one of the original exceptions to match #{original_exception_model}, but none are registered"
            else
                return "expected one of the original exceptions to match #{original_exception_model}, but got #{exception.original_exceptions.map(&:to_s).join(", ")}"
            end
        end
    end

    if !exception.failed_task
        if !(failure_point_matcher === exception.failed_generator)
            return "failure point #{exception.failed_generator} does not match #{failure_point_matcher}"
        end
    elsif failure_point_matcher.respond_to?(:task_matcher)
        if exception.failed_generator
            if !(failure_point_matcher === exception.failed_generator)
                return "failure point #{exception.failed_generator} does not match #{failure_point_matcher}"
            end
        else
            return "exception reports no failure generator but was expected to"
        end
    elsif !(failure_point_matcher === exception.failed_task)
        return "failure point #{exception.failed_task} does not match #{failure_point_matcher}"
    end
    nil
end
matches_task?(task) click to toggle source
# File lib/roby/queries/localized_error_matcher.rb, line 133
def matches_task?(task)
    if failure_point_matcher.respond_to?(:task_matcher)
        failure_point_matcher.task_matcher == task
    else failure_point_matcher === task
    end
end
to_execution_exception_matcher() click to toggle source
# File lib/roby/queries/localized_error_matcher.rb, line 142
def to_execution_exception_matcher
    Roby::Queries::ExecutionExceptionMatcher.new.with_exception(self)
end
to_s() click to toggle source
# File lib/roby/queries/localized_error_matcher.rb, line 125
def to_s
    description = "#{model}.with_origin(#{failure_point_matcher})"
    if original_exception_model
        description.concat(".with_original_exception(#{original_exception_model})")
    end
    description
end
with_model(model) click to toggle source

Specifies which subclass of LocalizedError this matcher should look for @return self

# File lib/roby/queries/localized_error_matcher.rb, line 27
def with_model(model)
    @model = model
    self
end
with_origin(plan_object_matcher) click to toggle source

Specifies a match on the error origin

The resulting match is extended, i.e. a task matcher will match the origin's task event if the origin itself is an event.

@return self

# File lib/roby/queries/localized_error_matcher.rb, line 51
def with_origin(plan_object_matcher)
    @failure_point_matcher = plan_object_matcher.match
    if failure_point_matcher.respond_to?(:generalized?) && !plan_object_matcher.respond_to?(:generalized?)
        failure_point_matcher.generalized
    end
    self
end
with_original_exception(model) click to toggle source

Specifies that the exception object should have an original_exception registered of the given model

Set to nil to allow for no original exception at all

# File lib/roby/queries/localized_error_matcher.rb, line 36
def with_original_exception(model)
    if model.respond_to?(:exception_matcher)
        @original_exception_model = model.exception_matcher
    else
        @original_exception_model = model
    end
    self
end