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



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/roby/exceptions.rb', line 90

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



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

def exception
  @exception
end

#generatorObject (readonly)

The origin EventGenerator if there is one



54
55
56
# File 'lib/roby/exceptions.rb', line 54

def generator
  @generator
end

#handledObject

If this specific exception has been marked has handled



59
60
61
# File 'lib/roby/exceptions.rb', line 59

def handled
  @handled
end

#traceRelations::BidirectionalDirectedAdjacencyGraph (readonly)

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



42
43
44
# File 'lib/roby/exceptions.rb', line 42

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)



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

def each_involved_task(&block)
    return enum_for(__method__) if !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)


51
# File 'lib/roby/exceptions.rb', line 51

def fatal?; exception.fatal? end

#forkObject

Create a sibling from this exception



108
109
110
# File 'lib/roby/exceptions.rb', line 108

def fork
    dup
end

#handled?Boolean

If this exception has been marked as handled

Returns:

  • (Boolean)


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

def handled?
    handled
end

#initialize_copy(from) ⇒ Object



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

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

#involved_task?(task) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

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

#originObject

The object from which the exception originates



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

def origin; @origin end

#originates_from?(object) ⇒ Boolean

True if this exception originates from the given task or generator

Returns:

  • (Boolean)


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

def originates_from?(object)
    generator == object || origin == object
end

#pretty_print(pp) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/roby/exceptions.rb', line 140

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



112
113
114
# File 'lib/roby/exceptions.rb', line 112

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



46
# File 'lib/roby/exceptions.rb', line 46

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

#reset_traceObject

Resets the trace to [origin]



76
77
78
79
# File 'lib/roby/exceptions.rb', line 76

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

#to_execution_exceptionObject



132
133
134
# File 'lib/roby/exceptions.rb', line 132

def to_execution_exception
    self
end

#to_sObject



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

def to_s
    PP.pp(self, '')
end