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, bindings) ⇒ WebdroneError

Returns a new instance of WebdroneError.



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

def initialize(msg, original = $!, a0, bindings)
  super(msg)
  @original = original
  @a0 = a0
  @buffer = []
  @binding = nil
  @location = nil

  begin
    # find location of user error
    bindings[0..-1].each_with_index do |binding, index|
      location = { path: binding.eval('__FILE__'), lineno: binding.eval('__LINE__') }
      if Gem.path.none? { |path| location[:path].include? path }
        @location = location
        @binding = binding
        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

#bindingObject (readonly)

Returns the value of attribute binding.



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

def binding
  @binding
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



44
45
46
47
48
49
# File 'lib/webdrone/error.rb', line 44

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



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

def report
  report_script
  report_screenshot
  report_os
  report_exception
  report_time
end

#report_exceptionObject



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

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
      else
        write_line sprintf "%02d:     from %s", index, location
      end
    end

    dump_error_report
  rescue
  end
end

#report_osObject



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

def report_os
  write_title "SYSTEM INFO"

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

  dump_error_report
end

#report_screenshotObject



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

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



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

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



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

def report_time
  write_title "#{Time.new}"

  dump_error_report
end

#write_line(line) ⇒ Object



29
30
31
32
33
# File 'lib/webdrone/error.rb', line 29

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

#write_title(title) ⇒ Object



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

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