Exception: Webdrone::WebdroneError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, original = $!, a0, caller_locations) ⇒ WebdroneError



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/webdrone/error.rb', line 5

def initialize(msg, original = $!, a0, caller_locations)
  super(msg)
  @original = original
  @a0 = a0
  @caller_locations = caller_locations
  @buffer = []

  begin
    # find location of user error
    @caller_locations[0..-1].each_with_index do |location, index|
      if Gem.path.none? { |path| location.path.include? path }
        @location = location
        @caller_location_index = index
        break
      end
    end

    report if a0.conf.error == :raise_report
  rescue
  end
end

Instance Attribute Details

#a0Object (readonly)

Returns the value of attribute a0.



3
4
5
# File 'lib/webdrone/error.rb', line 3

def a0
  @a0
end

#caller_location_indexObject (readonly)

Returns the value of attribute caller_location_index.



3
4
5
# File 'lib/webdrone/error.rb', line 3

def caller_location_index
  @caller_location_index
end

#caller_locationsObject (readonly)

Returns the value of attribute caller_locations.



3
4
5
# File 'lib/webdrone/error.rb', line 3

def caller_locations
  @caller_locations
end

#originalObject (readonly)

Returns the value of attribute original.



3
4
5
# File 'lib/webdrone/error.rb', line 3

def original
  @original
end

Instance Method Details

#dump_error_reportObject



42
43
44
45
46
47
# File 'lib/webdrone/error.rb', line 42

def dump_error_report
  File.open(File.join(@a0.conf.outdir, "a0_webdrone_error_report.txt"), "a") do |file|
    file.write(@buffer.join)
  end
  @buffer = []
end

#reportObject



49
50
51
52
53
54
55
# File 'lib/webdrone/error.rb', line 49

def report
  report_script
  report_screenshot
  report_os
  report_exception
  report_time
end

#report_exceptionObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/webdrone/error.rb', line 97

def report_exception
  begin
    write_title "EXCEPTION DUMP"

    write_line "#{@original.class}: #{@original.message}"
    @original.backtrace_locations.each_with_index do |location, index|
      if location.path == @location.path and location.lineno == @location.lineno
        write_line sprintf "%02d: ==> from %s", index, location
        @caller_index = index
      else
        write_line sprintf "%02d:     from %s", index, location
      end
    end

    dump_error_report
  rescue
  end
end

#report_osObject



116
117
118
119
120
121
122
123
# File 'lib/webdrone/error.rb', line 116

def report_os
  write_title "SYSTEM INFO"

  write_line "A0 WEBDRONE VERSION: #{Webdrone::VERSION}"
  write_line OS.report

  dump_error_report
end

#report_screenshotObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/webdrone/error.rb', line 78

def report_screenshot
  begin
    write_title "AUTOMATIC SCREENSHOT"
    begin
      @a0.ctxt.with_conf error: :raise do
        file = @a0.shot.screen 'a0_webdrone_error_report'
        write_line "Screenshot saved succesfully filename:"
        write_line "#{File.expand_path(file.path)}"
      end
    rescue => exception
      write_line "Error Saving screenshot, exception:"
      write_line "#{exception}"
    end

    dump_error_report
  rescue
  end
end

#report_scriptObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/webdrone/error.rb', line 57

def report_script
  begin
    ini, fin = [@location.lineno - 10 - 1, @location.lineno + 10 - 1]
    ini = 0 if ini < 0

    write_title "LOCATION OF ERROR"
    write_line "#{@location.path} AT LINE #{sprintf '%3d', @location.lineno}"
    File.readlines(@location.path)[ini..fin].each_with_index do |line, index|
      lno = index + ini + 1
      if lno == @location.lineno
        write_line sprintf "%3d ==> %s", lno, line
      else
        write_line sprintf "%3d     %s", lno, line
      end
    end

    dump_error_report
  rescue
  end
end

#report_timeObject



125
126
127
128
129
# File 'lib/webdrone/error.rb', line 125

def report_time
  write_title "#{Time.new}"

  dump_error_report
end

#write_line(line) ⇒ Object



27
28
29
30
31
# File 'lib/webdrone/error.rb', line 27

def write_line(line)
  line = "#{line.chomp}\r\n"
  @buffer << line
  puts line
end

#write_title(title) ⇒ Object



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

def write_title(title)
  title = "#{title} " if title.length % 2 != 0
  title = "== #{title} =="
  filler = "="
  length = (80 - title.length) / 2
  title = "#{filler*length}#{title}#{filler*length}\n" if length > 1
  write_line title
end