Class: Roby::ExecutionException

Inherits:
Object
  • Object
show all
Includes:
DRoby::V5::ExecutionExceptionDumper
Defined in:
lib/roby/exceptions.rb,
lib/roby/droby/enable.rb

Overview

ExecutionException objects are used during the exception handling stage to keep information about the propagation.

When a propagation fork is found (for instance, a task with two parents), two or more siblings are created with #fork. If at some point two siblings are to be handled by the same task, coming for instance from two different children, then they are merged with #merge to from one single ExecutionException object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DRoby::V5::ExecutionExceptionDumper

#droby_dump

Constructor Details

#initialize(exception) ⇒ ExecutionException

Creates a new execution exception object with the specified source If source is nil, tries to guess the source from exception: if exception responds to #task or #generator we use either #task or call #generator.task



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/roby/exceptions.rb', line 105

def initialize(exception)
    @exception = exception
    @trace = Relations::BidirectionalDirectedAdjacencyGraph.new

    if task = exception.failed_task
        @origin = task
        @trace.add_vertex(task)
    end
    if generator = exception.failed_generator
        @generator = exception.failed_generator
    end

    if !task && !generator
        raise ArgumentError, "invalid exception specification: cannot get the exception source"
    end
end

Instance Attribute Details

#exceptionObject (readonly)

The exception object



68
69
70
# File 'lib/roby/exceptions.rb', line 68

def exception
  @exception
end

#generatorObject (readonly)

The origin EventGenerator if there is one



66
67
68
# File 'lib/roby/exceptions.rb', line 66

def generator
  @generator
end

#handledObject

If this specific exception has been marked has handled



71
72
73
# File 'lib/roby/exceptions.rb', line 71

def handled
  @handled
end

#originObject (readonly)

The object from which the exception originates



57
58
59
# File 'lib/roby/exceptions.rb', line 57

def origin
  @origin
end

#traceRelations::BidirectionalDirectedAdjacencyGraph (readonly)

The trace of how this exception has been propagated in the plan so far



48
49
50
# File 'lib/roby/exceptions.rb', line 48

def trace
  @trace
end

Instance Method Details

#each_involved_task(&block) ⇒ Object

Enumerates all tasks that are involved in this exception (either origin or in the trace)



80
81
82
83
84
# File 'lib/roby/exceptions.rb', line 80

def each_involved_task(&block)
    return enum_for(__method__) unless block_given?

    trace.each_vertex(&block)
end

#fatal?Boolean

If true, the underlying exception is a fatal error, i.e. should cause parent tasks to be stopped if unhandled.

Returns:

  • (Boolean)


61
62
63
# File 'lib/roby/exceptions.rb', line 61

def fatal?
    exception.fatal?
end

#forkObject

Create a sibling from this exception



123
124
125
# File 'lib/roby/exceptions.rb', line 123

def fork
    dup
end

#handled?Boolean

If this exception has been marked as handled

Returns:

  • (Boolean)


74
75
76
# File 'lib/roby/exceptions.rb', line 74

def handled?
    handled
end

#initialize_copy(from) ⇒ Object



142
143
144
145
# File 'lib/roby/exceptions.rb', line 142

def initialize_copy(from)
    super
    @trace = from.trace.dup
end

#involved_task?(task) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/roby/exceptions.rb', line 86

def involved_task?(task)
    trace.has_vertex?(task)
end

#merge(sibling) ⇒ Object

Merges sibling into this object

Parameters:

  • edge_source (Roby::Task)

    the source of the edge in sibling that led to this merge

  • edge_target (Roby::Task)

    the target of the edge in sibling that led to this merge



137
138
139
140
# File 'lib/roby/exceptions.rb', line 137

def merge(sibling)
    @trace.merge(sibling.trace)
    self
end

#originates_from?(object) ⇒ Boolean

True if this exception originates from the given task or generator

Returns:

  • (Boolean)


97
98
99
# File 'lib/roby/exceptions.rb', line 97

def originates_from?(object)
    [generator, origin].include?(object)
end

#pretty_print(pp) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/roby/exceptions.rb', line 155

def pretty_print(pp)
    pp.text "from #{origin} with trace"
    pp.nest(2) do
        pp.nest(2) do
            trace.each_edge do |a, b, _|
                pp.breakable
                pp.text "#{a} => #{b}"
            end
        end
        pp.breakable
        pp.text "Exception:"
        pp.nest(2) do
            pp.breakable
            exception.pretty_print(pp)
        end
    end
end

#propagate(from, to) ⇒ Object



127
128
129
# File 'lib/roby/exceptions.rb', line 127

def propagate(from, to)
    trace.add_edge(from, to)
end

#propagation_leafsObject

The last object(s) that handled the exception. This is either a single object or an array



52
53
54
# File 'lib/roby/exceptions.rb', line 52

def propagation_leafs
    trace.each_vertex.find_all { |v| trace.leaf?(v) }
end

#reset_traceObject

Resets the trace to [origin]



91
92
93
94
# File 'lib/roby/exceptions.rb', line 91

def reset_trace
    @trace = Relations::BidirectionalDirectedAdjacencyGraph.new
    @trace.add_vertex(@origin)
end

#to_execution_exceptionObject



147
148
149
# File 'lib/roby/exceptions.rb', line 147

def to_execution_exception
    self
end

#to_sObject



151
152
153
# File 'lib/roby/exceptions.rb', line 151

def to_s
    PP.pp(self, "".dup)
end