Class: AppMap::Event::MethodReturn

Inherits:
MethodReturnIgnoreValue show all
Defined in:
lib/appmap/event.rb

Constant Summary

Constants inherited from MethodEvent

AppMap::Event::MethodEvent::LIMIT

Instance Attribute Summary collapse

Attributes inherited from MethodReturnIgnoreValue

#elapsed, #parent_id

Attributes inherited from MethodEventStruct

#event, #id, #thread_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MethodEvent

best_class_name, custom_display_string, default_display_string, display_string, object_properties

Instance Attribute Details

#exceptionsObject

Returns the value of attribute exceptions.



196
197
198
# File 'lib/appmap/event.rb', line 196

def exceptions
  @exceptions
end

#return_valueObject

Returns the value of attribute return_value.



196
197
198
# File 'lib/appmap/event.rb', line 196

def return_value
  @return_value
end

Class Method Details

.build_from_invocation(parent_id, return_value, exception, elapsed: nil, event: MethodReturn.new) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/appmap/event.rb', line 199

def build_from_invocation(parent_id, return_value, exception, elapsed: nil, event: MethodReturn.new)
  event ||= MethodReturn.new
  event.tap do |_|
    if return_value
      event.return_value = {
        class: best_class_name(return_value),
        value: display_string(return_value),
        object_id: return_value.__id__
      }
    end
    if exception
      next_exception = exception
      exceptions = []
      while next_exception
        exception_backtrace = next_exception.backtrace_locations.try(:[], 0)
        exceptions << {
          class: best_class_name(next_exception),
          message: display_string(next_exception.message),
          object_id: next_exception.__id__,
          path: exception_backtrace&.path,
          lineno: exception_backtrace&.lineno
        }.compact
        next_exception = next_exception.cause
      end

      event.exceptions = exceptions
    end
    MethodReturnIgnoreValue.build_from_invocation(parent_id, elapsed: elapsed, event: event)
  end
end

Instance Method Details

#to_hObject



231
232
233
234
235
236
# File 'lib/appmap/event.rb', line 231

def to_h
  super.tap do |h|
    h[:return_value] = return_value if return_value
    h[:exceptions] = exceptions if exceptions
  end
end