Class: RorVsWild::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/rorvswild/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, context = nil) ⇒ Error

Returns a new instance of Error.



9
10
11
12
13
# File 'lib/rorvswild/error.rb', line 9

def initialize(exception, context = nil)
  @exception = exception
  @file, @line = locator.find_most_relevant_file_and_line_from_exception(exception)
  @context = extract_context(context)
end

Instance Attribute Details

#detailsObject

Returns the value of attribute details.



7
8
9
# File 'lib/rorvswild/error.rb', line 7

def details
  @details
end

#exceptionObject (readonly)

Returns the value of attribute exception.



5
6
7
# File 'lib/rorvswild/error.rb', line 5

def exception
  @exception
end

Instance Method Details

#as_json(options = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rorvswild/error.rb', line 19

def as_json(options = nil)
  hash = {
    line: @line.to_i,
    file: locator.relative_path(@file),
    message: exception.message[0,1_000_000],
    backtrace: exception.backtrace || ["No backtrace"],
    exception: exception.class.to_s,
    context: @context,
    environment: Host.to_h,
  }
  hash.merge!(details) if details
  hash
end

#extract_context(given_context) ⇒ Object



33
34
35
36
37
38
# File 'lib/rorvswild/error.rb', line 33

def extract_context(given_context)
  hash = defined?(ActiveSupport::ExecutionContext) ? ActiveSupport::ExecutionContext.to_h : {}
  hash.merge!(RorVsWild.agent&.current_execution&.error_context || {})
  hash.merge!(given_context) if given_context.is_a?(Hash)
  hash
end

#locatorObject



15
16
17
# File 'lib/rorvswild/error.rb', line 15

def locator
  RorVsWild.agent.locator
end