Class: Roby::Queries::CodeErrorMatcher

Inherits:
LocalizedErrorMatcher show all
Defined in:
lib/roby/queries/code_error_matcher.rb

Overview

Matcher for CodeError exceptions

In addition to the LocalizedError properties, it allows to match properties on the Ruby exception that has been thrown

Instance Attribute Summary collapse

Attributes inherited from LocalizedErrorMatcher

#failure_point_matcher, #model, #original_exception_model

Attributes inherited from MatcherBase

#neg_predicates, #predicates

Instance Method Summary collapse

Methods inherited from LocalizedErrorMatcher

#matches_task?, #to_execution_exception_matcher, #with_model, #with_origin, #with_original_exception

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

#droby_dump

Methods inherited from MatcherBase

#&, declare_class_methods, #each, #indexed_query?, #match, match_predicate, match_predicates, #negate, #|

Constructor Details

#initializeCodeErrorMatcher

Returns a new instance of CodeErrorMatcher.



9
10
11
12
13
# File 'lib/roby/queries/code_error_matcher.rb', line 9

def initialize
    super
    @ruby_exception_class = ::Exception
    with_model(CodeError)
end

Instance Attribute Details

#ruby_exception_classObject (readonly)

Returns the value of attribute ruby_exception_class.



8
9
10
# File 'lib/roby/queries/code_error_matcher.rb', line 8

def ruby_exception_class
  @ruby_exception_class
end

Instance Method Details

#===(error) ⇒ Object



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

def ===(error)
    return false if !super
    ruby_exception_class === error.error
end

#describe_failed_match(exception) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/roby/queries/code_error_matcher.rb', line 44

def describe_failed_match(exception)
    if description = super
        return description
    elsif !(ruby_exception_class === exception.error)
        if ruby_exception_class
            return "the underlying exception #{exception.error} does not match the expected #{ruby_exception_class}"
        else
            return "there is an underlying exception (#{exception.error}) but the matcher expected none"
        end
    end
end

#to_sObject



35
36
37
38
39
40
41
42
# File 'lib/roby/queries/code_error_matcher.rb', line 35

def to_s
    description = super
    if ruby_exception_class
        description.concat(".with_ruby_exception(#{ruby_exception_class})")
    else
        description.concat(".without_ruby_exception")
    end
end

#with_ruby_exception(matcher) ⇒ Object

Match the underlying ruby exception

Parameters:

  • matcher (#===, Class)

    an object that can match an Exception object, usually an exception class



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

def with_ruby_exception(matcher)
    with_original_exception(matcher)
    @ruby_exception_class = matcher
    self
end

#without_ruby_exceptionObject

Match a CodeError without an original exception



26
27
28
# File 'lib/roby/queries/code_error_matcher.rb', line 26

def without_ruby_exception
    with_ruby_exception(nil)
end