Class: Roby::Queries::LocalizedErrorMatcher
- Inherits:
-
MatcherBase
- Object
- MatcherBase
- Roby::Queries::LocalizedErrorMatcher
- 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
Instance Attribute Summary collapse
-
#failure_point_matcher ⇒ #===
readonly
The object that will be used to match the error origin.
-
#model ⇒ Class
readonly
The exception class that should be matched.
-
#original_exception_model ⇒ #===?
readonly
Match object to validate the exception’s ExeptionBase#original_exceptions.
Attributes inherited from MatcherBase
Instance Method Summary collapse
-
#===(exception) ⇒ Boolean
True if the given execution exception object matches self, false otherwise.
- #describe_failed_match(exception) ⇒ Object
-
#initialize ⇒ LocalizedErrorMatcher
constructor
A new instance of LocalizedErrorMatcher.
- #matches_task?(task) ⇒ Boolean
- #to_execution_exception_matcher ⇒ Object
- #to_s ⇒ Object
-
#with_model(model) ⇒ Object
Specifies which subclass of LocalizedError this matcher should look for.
-
#with_origin(plan_object_matcher) ⇒ Object
Specifies a match on the error origin.
-
#with_original_exception(model) ⇒ Object
Specifies that the exception object should have an original_exception registered of the given model.
Methods included from DRoby::V5::Queries::LocalizedErrorMatcherDumper
Methods inherited from MatcherBase
#&, declare_class_methods, #each, #indexed_query?, #match, match_predicate, match_predicates, #negate, #|
Constructor Details
#initialize ⇒ LocalizedErrorMatcher
Returns a new instance of LocalizedErrorMatcher.
17 18 19 20 21 22 |
# 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 |
Instance Attribute Details
#failure_point_matcher ⇒ #=== (readonly)
Returns the object that will be used to match the error origin.
12 13 14 |
# File 'lib/roby/queries/localized_error_matcher.rb', line 12 def failure_point_matcher @failure_point_matcher end |
#model ⇒ Class (readonly)
Returns the exception class that should be matched. It must be a subclass of LocalizedError, and is LocalizedError by default.
9 10 11 |
# File 'lib/roby/queries/localized_error_matcher.rb', line 9 def model @model end |
#original_exception_model ⇒ #===? (readonly)
Returns match object to validate the exception’s ExeptionBase#original_exceptions.
15 16 17 |
# File 'lib/roby/queries/localized_error_matcher.rb', line 15 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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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) ⇒ Object
90 91 92 93 94 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 |
# 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) ⇒ Boolean
133 134 135 136 137 138 |
# 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 ⇒ Object
142 143 144 |
# 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 ⇒ Object
125 126 127 128 129 130 131 |
# 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) ⇒ Object
Specifies which subclass of LocalizedError this matcher should look for
27 28 29 30 |
# File 'lib/roby/queries/localized_error_matcher.rb', line 27 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.
51 52 53 54 55 56 57 |
# 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) ⇒ 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
36 37 38 39 40 41 42 43 |
# 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 |