Class: Roby::Queries::LocalizedErrorMatcher

Inherits:
MatcherBase show all
Includes:
DRoby::V5::Queries::LocalizedErrorMatcherDumper
Defined in:
lib/roby/queries/localized_error_matcher.rb,
lib/roby/droby/enable.rb

Overview

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

Direct Known Subclasses

CodeErrorMatcher

Instance Attribute Summary collapse

Attributes inherited from MatcherBase

#neg_predicates, #predicates

Instance Method Summary collapse

Methods included from DRoby::V5::Queries::LocalizedErrorMatcherDumper

#droby_dump

Methods inherited from MatcherBase

#&, #add_neg_predicate, #add_predicate, declare_class_methods, #each, #each_in_plan, #indexed_query?, #match, match_predicate, match_predicates, #negate, #reset, #to_a, #to_set, #|

Constructor Details

#initializeLocalizedErrorMatcher

Returns a new instance of LocalizedErrorMatcher.



19
20
21
22
23
24
25
# File 'lib/roby/queries/localized_error_matcher.rb', line 19

def initialize
    super
    @model = LocalizedError
    @failure_point_matcher = Queries.any
    @emitted = false
    @original_exception_model = nil
end

Instance Attribute Details

#failure_point_matcher#=== (readonly)

Returns the object that will be used to match the error origin.

Returns:

  • (#===)

    the object that will be used to match the error origin



14
15
16
# File 'lib/roby/queries/localized_error_matcher.rb', line 14

def failure_point_matcher
  @failure_point_matcher
end

#modelClass (readonly)

Returns the exception class that should be matched. It must be a subclass of LocalizedError, and is LocalizedError by default.

Returns:

  • (Class)

    the exception class that should be matched. It must be a subclass of LocalizedError, and is LocalizedError by default



11
12
13
# File 'lib/roby/queries/localized_error_matcher.rb', line 11

def model
  @model
end

#original_exception_model#===? (readonly)

Returns match object to validate the exception’s ExeptionBase#original_exceptions.

Returns:

  • (#===, nil)

    match object to validate the exception’s ExeptionBase#original_exceptions



17
18
19
# File 'lib/roby/queries/localized_error_matcher.rb', line 17

def original_exception_model
  @original_exception_model
end

Instance Method Details

#===(exception) ⇒ Boolean

Returns true if the given execution exception object matches self, false otherwise.

Returns:

  • (Boolean)

    true if the given execution exception object matches self, false otherwise



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/roby/queries/localized_error_matcher.rb', line 71

def ===(exception)
    return false unless model === exception
    return false if @emitted && !exception.failed_event

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

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

    original_exception || true
end

#describe_failed_match(exception) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/roby/queries/localized_error_matcher.rb', line 95

def describe_failed_match(exception)
    unless 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 }
        unless original_exception
            if exception.original_exceptions.empty?
                return "expected one of the original exceptions "\
                       "to match #{original_exception_model}, "\
                       "but none are registered"
            else
                original_exceptions_s =
                    exception.original_exceptions.map(&:to_s).join(", ")
                return "expected one of the original exceptions to "\
                       "match #{original_exception_model}, but got "\
                       "#{original_exceptions_s}"
            end
        end
    end

    if !exception.failed_task
        unless 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
            unless 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

#emittedObject

If the failure point matcher is a generator matcher, require that the failure origin is an actual emission



64
65
66
67
# File 'lib/roby/queries/localized_error_matcher.rb', line 64

def emitted
    @emitted = true
    self
end

#matches_task?(task) ⇒ Boolean

Returns:

  • (Boolean)


148
149
150
151
152
153
154
# File 'lib/roby/queries/localized_error_matcher.rb', line 148

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_matcherObject



158
159
160
# File 'lib/roby/queries/localized_error_matcher.rb', line 158

def to_execution_exception_matcher
    Roby::Queries::ExecutionExceptionMatcher.new.with_exception(self)
end

#to_sObject



140
141
142
143
144
145
146
# File 'lib/roby/queries/localized_error_matcher.rb', line 140

def to_s
    description = "#{model}.with_origin(#{failure_point_matcher})"
    if original_exception_model
        description += ".with_original_exception(#{original_exception_model})"
    end
    description
end

#with_model(model) ⇒ Object

Specifies which subclass of LocalizedError this matcher should look for

Returns:

  • self



30
31
32
33
# File 'lib/roby/queries/localized_error_matcher.rb', line 30

def with_model(model)
    @model = model
    self
end

#with_origin(plan_object_matcher) ⇒ Object

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.

Returns:

  • self



54
55
56
57
58
59
60
# File 'lib/roby/queries/localized_error_matcher.rb', line 54

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) ⇒ Object

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



39
40
41
42
43
44
45
46
# File 'lib/roby/queries/localized_error_matcher.rb', line 39

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