1 | # ---------------------------------------------------------------------- |
---|
2 | # UTILITY: bugreport |
---|
3 | # |
---|
4 | # This redefines the usual Tcl bgerror command to install a nicer |
---|
5 | # looking bug handler. |
---|
6 | # ====================================================================== |
---|
7 | # AUTHOR: Michael McLennan, Purdue University |
---|
8 | # Copyright (c) 2004-2006 Purdue Research Foundation |
---|
9 | # |
---|
10 | # See the file "license.terms" for information on usage and |
---|
11 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
12 | # ====================================================================== |
---|
13 | |
---|
14 | option add *BugReport*banner*foreground white startupFile |
---|
15 | option add *BugReport*banner*background #a9a9a9 startupFile |
---|
16 | option add *BugReport*banner*highlightBackground #a9a9a9 startupFile |
---|
17 | option add *BugReport*banner*font \ |
---|
18 | -*-helvetica-bold-r-normal-*-18-* startupFile |
---|
19 | option add *BugReport*expl.font \ |
---|
20 | -*-helvetica-medium-r-normal-*-12-* startupFile |
---|
21 | option add *BugReport*expl.wrapLength 3i startupFile |
---|
22 | |
---|
23 | namespace eval Rappture::bugreport { # forward declaration } |
---|
24 | |
---|
25 | # ---------------------------------------------------------------------- |
---|
26 | # USAGE: install |
---|
27 | # |
---|
28 | # Called once in the main program to install this bug reporting |
---|
29 | # facility. Any unexpected errors after this call will be handled |
---|
30 | # by this mechanism. |
---|
31 | # ---------------------------------------------------------------------- |
---|
32 | proc Rappture::bugreport::install {} { |
---|
33 | proc ::bgerror {err} { ::Rappture::bugreport::activate $err } |
---|
34 | } |
---|
35 | |
---|
36 | # ---------------------------------------------------------------------- |
---|
37 | # USAGE: activate <error> |
---|
38 | # |
---|
39 | # Used internally to pop up the bug handler whenver a bug is |
---|
40 | # encountered. Tells the user that there is a bug and logs the |
---|
41 | # problem, so it can be fixed. |
---|
42 | # ---------------------------------------------------------------------- |
---|
43 | proc Rappture::bugreport::activate {err} { |
---|
44 | global errorInfo |
---|
45 | |
---|
46 | set w [winfo reqwidth .bugreport] |
---|
47 | set h [winfo reqheight .bugreport] |
---|
48 | set x [expr {([winfo screenwidth .bugreport]-$w)/2}] |
---|
49 | set y [expr {([winfo screenheight .bugreport]-$w)/2}] |
---|
50 | |
---|
51 | wm geometry .bugreport +$x+$y |
---|
52 | wm deiconify .bugreport |
---|
53 | raise .bugreport |
---|
54 | |
---|
55 | .bugreport.details.text configure -state normal |
---|
56 | .bugreport.details.text delete 1.0 end |
---|
57 | .bugreport.details.text insert end "$err\n-----\n$errorInfo" |
---|
58 | .bugreport.details.text configure -state disabled |
---|
59 | # should log the error someday too... |
---|
60 | |
---|
61 | catch {grab set .bugreport} |
---|
62 | } |
---|
63 | |
---|
64 | # ---------------------------------------------------------------------- |
---|
65 | # USAGE: deactivate |
---|
66 | # |
---|
67 | # Used internally to take down the bug handler dialog. |
---|
68 | # ---------------------------------------------------------------------- |
---|
69 | proc Rappture::bugreport::deactivate {} { |
---|
70 | grab release .bugreport |
---|
71 | wm withdraw .bugreport |
---|
72 | |
---|
73 | # reset the grab in case it's hosed |
---|
74 | Rappture::grab::reset |
---|
75 | } |
---|
76 | |
---|
77 | # ---------------------------------------------------------------------- |
---|
78 | # USAGE: submit <stackTrace> |
---|
79 | # |
---|
80 | # Clients use this to send bug reports back to the hub site. Errors |
---|
81 | # are posted to a URL that creates a support ticket. |
---|
82 | # ---------------------------------------------------------------------- |
---|
83 | proc Rappture::bugreport::submit {stackTrace} { |
---|
84 | global tcl_platform |
---|
85 | |
---|
86 | package require http |
---|
87 | package require tls |
---|
88 | http::register https 443 ::tls::socket |
---|
89 | |
---|
90 | if {![regexp {^([^\n]+)\n} $stackTrace match summary]} { |
---|
91 | if {[string length $stackTrace] == 0} { |
---|
92 | set summary "Unexpected error from Rappture" |
---|
93 | } else { |
---|
94 | set summary $stackTrace |
---|
95 | } |
---|
96 | } |
---|
97 | if {[string length $summary] > 50} { |
---|
98 | set summary "[string range $summary 0 50]..." |
---|
99 | } |
---|
100 | append summary " (in tool \"[Rappture::Tool::get -name]\")" |
---|
101 | |
---|
102 | set query [http::formatQuery \ |
---|
103 | option com_support \ |
---|
104 | task create \ |
---|
105 | no_html 1 \ |
---|
106 | report $stackTrace |
---|
107 | login $tcl_platform(user) \ |
---|
108 | email "" \ |
---|
109 | hostname [info hostname] \ |
---|
110 | category rappture \ |
---|
111 | summary $summary \ |
---|
112 | referrer "tool \"[Rappture::Tool::get -name]\"" \ |
---|
113 | ] |
---|
114 | |
---|
115 | puts "avoid hard-coded web site URL!" |
---|
116 | set url https://zooley.nanohub.org/index2.php |
---|
117 | set token [http::geturl $url -query $query] |
---|
118 | |
---|
119 | if {[http::ncode] != 200} { |
---|
120 | error [http::code] |
---|
121 | } |
---|
122 | upvar #0 $token rval |
---|
123 | if {[regexp {Ticket #[0-9]+ \((.*:?)\) [0-9]+ times} $rval(body) match]} { |
---|
124 | return $match |
---|
125 | } |
---|
126 | error "Report received, but ticket may not have been filed" |
---|
127 | } |
---|
128 | |
---|
129 | # ---------------------------------------------------------------------- |
---|
130 | # Build the bug reporting dialog |
---|
131 | # ---------------------------------------------------------------------- |
---|
132 | toplevel .bugreport -class BugReport -borderwidth 1 -relief solid |
---|
133 | wm overrideredirect .bugreport 1 |
---|
134 | wm withdraw .bugreport |
---|
135 | |
---|
136 | frame .bugreport.banner -background #a9a9a9 |
---|
137 | pack .bugreport.banner -side top -fill x |
---|
138 | label .bugreport.banner.icon -image [Rappture::icon alert] |
---|
139 | pack .bugreport.banner.icon -side left -padx 2 -pady 2 |
---|
140 | label .bugreport.banner.title -text "Oops! Unexpected Error" |
---|
141 | pack .bugreport.banner.title -side left -padx {0 8} -pady 2 |
---|
142 | |
---|
143 | button .bugreport.ok -text "OK" -command Rappture::bugreport::deactivate |
---|
144 | pack .bugreport.ok -side bottom -pady {0 8} |
---|
145 | |
---|
146 | label .bugreport.expl -text "You've found a bug in this application.\n\nIf it's not a serious bug, you may be able to continue using the tool. But if the tool doesn't seem to behave properly after this, please close this session and start the tool again.\n\nYou can help us improve nanoHUB by reporting this error. Click on the \"Report Problems\" link in the web page containing this tool session, and tell us what you were doing when the error occurred." -justify left |
---|
147 | pack .bugreport.expl -padx 8 -pady 8 |
---|
148 | |
---|
149 | bind .bugreport.expl <Control-1><Control-1><Control-3><Control-3> { |
---|
150 | pack forget .bugreport.expl |
---|
151 | pack .bugreport.details -after .bugreport.ok \ |
---|
152 | -expand yes -fill both -padx 8 -pady 8 |
---|
153 | } |
---|
154 | |
---|
155 | bind .bugreport.expl <Control-1><Control-1><Control-Shift-1><Control-Shift-1> { |
---|
156 | pack forget .bugreport.expl |
---|
157 | pack .bugreport.details -after .bugreport.ok \ |
---|
158 | -expand yes -fill both -padx 8 -pady 8 |
---|
159 | } |
---|
160 | |
---|
161 | Rappture::Scroller .bugreport.details -xscrollmode auto -yscrollmode auto |
---|
162 | text .bugreport.details.text -wrap none |
---|
163 | .bugreport.details contents .bugreport.details.text |
---|
164 | |
---|
165 | # this binding keeps the bugreport window on top |
---|
166 | bind BugReportOnTop <ButtonPress> { |
---|
167 | wm deiconify %W |
---|
168 | raise %W |
---|
169 | } |
---|
170 | set btags [bindtags .bugreport] |
---|
171 | bindtags .bugreport [linsert $btags 0 BugReportOnTop] |
---|