equal
deleted
inserted
replaced
1 """ |
1 """ |
2 Build error messages |
2 Build error messages |
3 """ |
3 """ |
4 |
4 |
5 import traceback, sys, cgi, urllib |
5 import traceback, sys, cgi, urllib |
|
6 |
|
7 def truncate (msg, limit) : |
|
8 """ |
|
9 Truncate the given message to <limit> chars |
|
10 """ |
|
11 |
|
12 if len(msg) > limit : |
|
13 return msg[:limit-3] + '...' |
|
14 |
|
15 else : |
|
16 return msg |
6 |
17 |
7 def build_error (exc_info=None, env=None) : |
18 def build_error (exc_info=None, env=None) : |
8 """ |
19 """ |
9 Dumps out a raw traceback of the given/current exception to stdout. |
20 Dumps out a raw traceback of the given/current exception to stdout. |
10 |
21 |
49 |
60 |
50 except : |
61 except : |
51 version = None |
62 version = None |
52 |
63 |
53 # the exception type |
64 # the exception type |
54 exception_str = traceback.format_exception_only(*exc_info[:2])[-1][:255] |
65 exception_str = traceback.format_exception_only(*exc_info[:2])[-1] |
55 |
66 |
56 # the exception traceback |
67 # the exception traceback |
57 traceback_lines = traceback.format_exception(*exc_info) |
68 traceback_lines = traceback.format_exception(*exc_info) |
58 |
69 |
59 # XXX: make this configureable |
70 # XXX: make this configureable |
70 |
81 |
71 if version : |
82 if version : |
72 submit_args['revision'] = version |
83 submit_args['revision'] = version |
73 |
84 |
74 if exception_str : |
85 if exception_str : |
75 submit_args['summary'] = exception_str |
86 submit_args['summary'] = truncate(exception_str, 140) |
76 |
87 |
77 if traceback_lines : |
88 if traceback_lines : |
78 # this is big |
89 # this is big |
79 submit_args['description'] = """\ |
90 submit_args['description'] = """\ |
80 [Insert any additional information here] |
91 [Insert any additional information here] |
106 <pre>%(traceback)s</pre> |
117 <pre>%(traceback)s</pre> |
107 </body></html>""" % dict( |
118 </body></html>""" % dict( |
108 traceback = cgi.escape(''.join(traceback_lines)), |
119 traceback = cgi.escape(''.join(traceback_lines)), |
109 query_url = query_url, |
120 query_url = query_url, |
110 submit_url = submit_url, |
121 submit_url = submit_url, |
111 submit_url_short = submit_url[:120] + '...' |
122 submit_url_short = truncate(submit_url, 120) |
112 )).encode('utf-8')) |
123 )).encode('utf-8')) |
113 |
124 |