Exception: Webdrone::WebdroneError
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- Webdrone::WebdroneError
- Defined in:
- lib/webdrone/error.rb
Instance Attribute Summary collapse
-
#a0 ⇒ Object
readonly
Returns the value of attribute a0.
-
#binding ⇒ Object
readonly
Returns the value of attribute binding.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
Instance Method Summary collapse
- #dump_error_report ⇒ Object
-
#initialize(msg, original, a0, bindings) ⇒ WebdroneError
constructor
A new instance of WebdroneError.
- #report ⇒ Object
- #report_exception ⇒ Object
- #report_os ⇒ Object
- #report_screenshot ⇒ Object
- #report_script ⇒ Object
- #report_time ⇒ Object
- #write_line(line) ⇒ Object
- #write_title(title) ⇒ Object
Constructor Details
#initialize(msg, original, a0, bindings) ⇒ WebdroneError
Returns a new instance of WebdroneError.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/webdrone/error.rb', line 7 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..].each do |binding| location = { path: binding.source_location[0], lineno: binding.source_location[1] } next unless Gem.path.none? { |path| location[:path].include? path } @location = location @binding = binding break end report if a0.conf.error == :raise_report rescue StandardError nil end end |
Instance Attribute Details
#a0 ⇒ Object (readonly)
Returns the value of attribute a0.
5 6 7 |
# File 'lib/webdrone/error.rb', line 5 def a0 @a0 end |
#binding ⇒ Object (readonly)
Returns the value of attribute binding.
5 6 7 |
# File 'lib/webdrone/error.rb', line 5 def binding @binding end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
5 6 7 |
# File 'lib/webdrone/error.rb', line 5 def original @original end |
Instance Method Details
#dump_error_report ⇒ Object
48 49 50 51 52 53 |
# File 'lib/webdrone/error.rb', line 48 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 |
#report ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/webdrone/error.rb', line 55 def report report_script report_screenshot report_os report_exception report_time end |
#report_exception ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/webdrone/error.rb', line 101 def report_exception write_title "EXCEPTION DUMP" write_line "#{@original.class}: #{@original.}" @original.backtrace_locations.each_with_index do |location, index| if location.path == @location[:path] && location.lineno == @location[:lineno] write_line sprintf "%02d: ==> from #{location}", index else write_line sprintf "%02d: from #{location}", index end end dump_error_report rescue StandardError nil end |
#report_os ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/webdrone/error.rb', line 118 def report_os write_title "SYSTEM INFO" write_line "A0 WEBDRONE VERSION: #{Webdrone::VERSION}" write_line OS.report dump_error_report end |
#report_screenshot ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/webdrone/error.rb', line 83 def report_screenshot 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.(file.path).to_s end rescue StandardError => error write_line "Error Saving screenshot, exception:" write_line error.to_s end dump_error_report rescue StandardError nil end |
#report_script ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/webdrone/error.rb', line 63 def report_script ini, fin = [@location[:lineno] - 10 - 1, @location[:lineno] + 10 - 1] ini = 0 if ini.negative? write_title "LOCATION OF ERROR" write_line "#{@location[:path]} AT LINE #{sprintf '%<location>3d', location: @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 ==> #{line}", lno else write_line sprintf "%3d #{line}", lno end end dump_error_report rescue StandardError nil end |
#report_time ⇒ Object
127 128 129 130 131 |
# File 'lib/webdrone/error.rb', line 127 def report_time write_title Time.new.to_s dump_error_report end |
#write_line(line) ⇒ Object
32 33 34 35 36 |
# File 'lib/webdrone/error.rb', line 32 def write_line(line) line = "#{line.chomp}\r\n" @buffer << line puts line end |
#write_title(title) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/webdrone/error.rb', line 38 def write_title(title) title = "#{title} " if title.length.odd? title = "== #{title} ==" filler = "=" length = (80 - title.length) / 2 filler_length = filler * length title = "#{filler_length}#{title}#{filler_length}\n" if length > 1 write_line title end |