Exception: Webdrone::WebdroneError
- Inherits:
-
StandardError
- Object
- StandardError
- Webdrone::WebdroneError
- Defined in:
- lib/webdrone/error.rb
Instance Attribute Summary collapse
-
#a0 ⇒ Object
readonly
Returns the value of attribute a0.
-
#caller_locations ⇒ Object
readonly
Returns the value of attribute caller_locations.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
Instance Method Summary collapse
- #dump_error_report ⇒ Object
-
#initialize(msg, original = $!, a0, caller_locations) ⇒ WebdroneError
constructor
A new instance of WebdroneError.
- #report_exception ⇒ Object
- #report_screenshot ⇒ Object
- #report_script ⇒ Object
- #report_time ⇒ Object
- #write_line(line) ⇒ Object
- #write_title(title) ⇒ Object
Constructor Details
#initialize(msg, original = $!, a0, caller_locations) ⇒ WebdroneError
Returns a new instance of WebdroneError.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/webdrone/error.rb', line 4 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[1..-1].each do |location| if not location.path.include? 'lib/webdrone/' @location = location break end end report_script report_screenshot report_exception report_time rescue end end |
Instance Attribute Details
#a0 ⇒ Object (readonly)
Returns the value of attribute a0.
3 4 5 |
# File 'lib/webdrone/error.rb', line 3 def a0 @a0 end |
#caller_locations ⇒ Object (readonly)
Returns the value of attribute caller_locations.
3 4 5 |
# File 'lib/webdrone/error.rb', line 3 def caller_locations @caller_locations end |
#original ⇒ Object (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_report ⇒ Object
43 44 45 46 47 48 |
# File 'lib/webdrone/error.rb', line 43 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_exception ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/webdrone/error.rb', line 81 def report_exception begin write_title "EXCEPTION DUMP" write_line "#{@original.class}: #{@original.}" @original.backtrace_locations.each do |location| if location.path == @location.path and location.lineno == @location.lineno write_line sprintf " ==> from %s", location else write_line sprintf " from %s", location end end dump_error_report rescue end end |
#report_screenshot ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/webdrone/error.rb', line 70 def report_screenshot begin write_title "AUTOMATIC SCREENSHOT" file = @a0.shot.screen 'a0_webdrone_error_report' write_line "Saved: #{file.path}" dump_error_report rescue end end |
#report_script ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/webdrone/error.rb', line 50 def report_script begin ini, fin = [@location.lineno - 10 - 1, @location.lineno + 10 - 1] ini = 0 if ini < 0 write_title "#{@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_time ⇒ Object
99 100 101 102 103 |
# File 'lib/webdrone/error.rb', line 99 def report_time write_title "#{Time.new}" dump_error_report end |
#write_line(line) ⇒ Object
28 29 30 31 32 |
# File 'lib/webdrone/error.rb', line 28 def write_line(line) line = "#{line.chomp}\r\n" @buffer << line puts line end |
#write_title(title) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/webdrone/error.rb', line 34 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 |