Class: QDA::GUI::CrashReportDialog

Inherits:
Wx::Dialog
  • Object
show all
Defined in:
lib/weft/wxgui/error_handler.rb

Overview

to a crash report CGI.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, exception) ⇒ CrashReportDialog

Returns a new instance of CrashReportDialog.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/weft/wxgui/error_handler.rb', line 14

def initialize(parent, exception)
  super(nil, -1, Lang::CRASH_REPORT_TITLE)
  @err = exception

  @panel = Wx::Panel.new(self)
  sizer = Wx::BoxSizer.new(Wx::VERTICAL)
  text = Wx::StaticText.new(panel, -1, Lang::CRASH_REPORT_MESSAGE)
  sizer.add(text, 0, Wx::ALL, 8)
  sizer.add( construct_crash_report_form , 1, Wx::GROW|Wx::ALL, 5)    
  sizer.add( construct_send_buttons, 0,
            Wx::GROW|Wx::ADJUST_MINSIZE|Wx::ALIGN_BOTTOM, 8)

  panel.set_sizer(sizer)
  self.client_size = Wx::Size.new(400, 500)
end

Instance Attribute Details

#errObject

Returns the value of attribute err.



10
11
12
# File 'lib/weft/wxgui/error_handler.rb', line 10

def err
  @err
end

Class Method Details

.display(*args) ⇒ Object



30
31
32
# File 'lib/weft/wxgui/error_handler.rb', line 30

def self.display(*args)
  new(*args).show_modal()
end

Instance Method Details

#construct_crash_report_formObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/weft/wxgui/error_handler.rb', line 107

def construct_crash_report_form()
  report_box = Wx::StaticBox.new(panel, -1, Lang::CRASH_REPORT)
  report_box_sizer = Wx::StaticBoxSizer.new(report_box, Wx::VERTICAL)
  
  email_label = Wx::StaticText.new(panel, -1, Lang::CRASH_REPORT_EMAIL) 
  report_box_sizer.add(email_label, 0, Wx::ALL, 3)
  @email_box   = Wx::TextCtrl.new(panel, -1, '')
  report_box_sizer.add(@email_box, 0, Wx::ALL|Wx::GROW, 3)
  
  info_label = Wx::StaticText.new(panel, -1, Lang::CRASH_REPORT_INFO) 
  report_box_sizer.add(info_label, 0, Wx::ALL, 3)
  @info_box   = Wx::TextCtrl.new(panel, -1, '')
  report_box_sizer.add(@info_box, 0, Wx::ALL|Wx::GROW, 3)

  data_label = Wx::StaticText.new(panel, -1, Lang::CRASH_REPORT_DATA) 
  report_box_sizer.add(data_label, 0, Wx::ALL, 2)
  
  @text_box = Wx::TextCtrl.new(panel, -1, crash_details_string(),
                               DEF_POS, DEF_SIZE, 
                               Wx::TE_MULTILINE|Wx::TE_RICH|
                               Wx::TE_NOHIDESEL|Wx::TE_READONLY )
  report_box_sizer.add(@text_box, 1, Wx::ALL|Wx::GROW, 3)
  return report_box_sizer
end

#construct_send_buttonsObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/weft/wxgui/error_handler.rb', line 133

def construct_send_buttons()
  butt_panel = Wx::Panel.new(panel)
  bott_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)

  button = Wx::Button.new(butt_panel, -1, "Don't Send")
  button.evt_button(button.get_id) { | e | on_dont_send() }
  bott_sizer.add(button, 1, Wx::ALL, 4)

  button = Wx::Button.new(butt_panel, -1, 'Send')
  button.evt_button(button.get_id) { on_send }
  bott_sizer.add(button, 1, Wx::ALL, 4)
  butt_panel.set_sizer(bott_sizer)
  return butt_panel  
end

#crash_detailsObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/weft/wxgui/error_handler.rb', line 42

def crash_details()
  @crash ||= { 'when'         => Time.now.to_s(),
               'os'           => Config::CONFIG['target_os'],
               'config'       => Config::CONFIG['build'],
               'weft_version' => WEFT_VERSION_STRING,
               'ruby_version' => [ Config::CONFIG['MAJOR'], 
                                   Config::CONFIG['MINOR'], 
                                   Config::CONFIG['TEENY'] ].join('.'),
               'rs2exe'       => rs2exe,
               'backtrace'    => sanitised_backtrace_string(@err) }
end

#crash_details_stringObject



69
70
71
72
73
74
# File 'lib/weft/wxgui/error_handler.rb', line 69

def crash_details_string
  %w[when weft_version os config 
     ruby_version rs2exe backtrace].inject('') do | str, key |
    str << "#{key}: #{crash_details[key]}\n"
  end
end

#encoded_crash_detailsObject



77
78
79
80
81
82
83
# File 'lib/weft/wxgui/error_handler.rb', line 77

def encoded_crash_details()
  str = crash_details.keys.inject('') do | str, key |
    str << URI.encode(key) << '=' << URI.encode(crash_details[key]) << '&'
  end
  str << URI.encode('email') << '=' << URI.encode(@email_box.value) << '&'
  str << URI.encode('info') << '=' << URI.encode(@info_box.value)
end

#on_dont_sendObject



86
87
88
# File 'lib/weft/wxgui/error_handler.rb', line 86

def on_dont_send()
  end_modal(Wx::ID_CANCEL)
end

#on_sendObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/weft/wxgui/error_handler.rb', line 91

def on_send()
  disable()
  Wx::BusyCursor.busy do
    # see weft/wxgui/constants.rb for CRASH_REPORT_URL
    Net::HTTP.start(CRASH_REPORT_URL.host, 80) do | http |
      response = http.post(CRASH_REPORT_URL.path, encoded_crash_details)
      if response.code != '204'
        ErrorDialog.display( Lang::FAILED_CRASH_SEND_TITLE, 
                             Lang::FAILED_CRASH_SEND_MESSAGE %
                             response.inspect )
      end
   end
 end
 end_modal(Wx::ID_OK)
end

#rs2exeObject



34
35
36
37
38
39
40
# File 'lib/weft/wxgui/error_handler.rb', line 34

def rs2exe
 if defined? ::RUBYSCRIPT2EXE_EEEEXE
   return ::RUBYSCRIPT2EXE_EEEEXE
 else
   return ''
 end
end

#sanitised_backtrace_string(exception) ⇒ Object

return a stringified version of the exception backtrace, removing any information about the containing filesystem



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/weft/wxgui/error_handler.rb', line 56

def sanitised_backtrace_string(exception)
  backtrace = [ err.inspect ] + err.backtrace
  
  # check where the libraries are being loaded from
  lib_dir = File.expand_path( File.join( File.dirname(__FILE__), 
                                         '..', '..', '..') )
  lib_dir_rx = /#{Regexp.escape(lib_dir)}/

  # remove this information from backtrace
  backtrace.map! { | line | line.sub(lib_dir_rx, '') }
  backtrace.join("\n")
end