Module: Roby::TaskStructure::ErrorHandling::Extension

Defined in:
lib/roby/task_structure/error_handling.rb

Instance Method Summary collapse

Instance Method Details

#being_repaired? ⇒ Boolean

Test if this task has an active repair tasks associated

Returns:

  • (Boolean)


111
112
113
# File 'lib/roby/task_structure/error_handling.rb', line 111

def being_repaired?
    each_child_object(ErrorHandling).any?(&:running?)
end

#can_handle_error?(exception) ⇒ Boolean

Tests if this task can handle the provided exception, either because it is an error repair task itself, or because it has one attached.

It is different from #handles_error? as the latter tests whether this task is currently handling the exception, while this one only tests if it could (usually, the difference is whether this task is running)

Returns:

  • (Boolean)


91
92
93
94
95
# File 'lib/roby/task_structure/error_handling.rb', line 91

def can_handle_error?(exception)
    exception = exception.to_execution_exception
    can_repair_error?(exception) ||
        !find_all_matching_repair_tasks(exception).empty?
end

#can_repair_error?(exception) ⇒ Boolean

Tests if this task can be used to repair an exception

It is different from #repairs_error? as the latter tests whether this task is currently repairing such an exception, while this one only tests if it could (usually, the difference is whether this task is running)

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/roby/task_structure/error_handling.rb', line 49

def can_repair_error?(exception)
    return if finished?

    exception = exception.to_execution_exception
    repaired_tasks.each do |repaired|
        matchers = repaired[self, ErrorHandling]
        if matchers.any? { |m| m === exception }
            return true
        end
    end
    false
end

#failed_task ⇒ Object



36
37
38
39
# File 'lib/roby/task_structure/error_handling.rb', line 36

def failed_task
    # For backward compatibility only. One should use #repaired_tasks
    repaired_tasks.first
end

#find_all_matching_repair_tasks(exception) ⇒ Object

Returns the set of repair tasks attached to self that match the given exception



71
72
73
74
75
76
77
78
79
80
# File 'lib/roby/task_structure/error_handling.rb', line 71

def find_all_matching_repair_tasks(exception)
    exception = exception.to_execution_exception
    result = []
    each_error_handler do |child, matchers|
        next if child.finished?

        result << child if matchers.any? { |m| m === exception }
    end
    result
end

#handles_error?(exception) ⇒ Boolean

Tests if this task is currently handling the provided exception, either because it is an error repair task itself, or because it has one attached.

Returns:

  • (Boolean)


102
103
104
105
106
107
108
# File 'lib/roby/task_structure/error_handling.rb', line 102

def handles_error?(exception)
    return unless plan

    exception = exception.to_execution_exception
    ((running? || starting?) && can_repair_error?(exception)) ||
        find_all_matching_repair_tasks(exception).any? { |t| t.starting? || t.running? }
end

#repaired_tasks ⇒ Object



32
33
34
# File 'lib/roby/task_structure/error_handling.rb', line 32

def repaired_tasks
    each_parent_object(ErrorHandling).to_a
end

#repairs_error?(exception) ⇒ Boolean

Tests whether the given exception is handled by this task or by a repair handler attached to this task

Returns:

  • (Boolean)


64
65
66
67
# File 'lib/roby/task_structure/error_handling.rb', line 64

def repairs_error?(exception)
    exception = exception.to_execution_exception
    running? && can_repair_error?(exception)
end