1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
5 Unexpected exception handler
7 __author__
= 'Michal Čihař'
8 __email__
= 'michal@cihar.com'
10 Copyright © 2003 - 2009 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 from hashlib
import md5
as md5
30 from md5
import new
as md5
32 import Wammu
.ErrorMessage
33 from Wammu
.Locales
import StrConv
35 # set later in Wammu.App to have correct parent here
40 def Handler(errtype
, value
, tback
):
41 """User friendly error handling """
43 # prepare traceback text
44 trace
= traceback
.extract_tb(tback
)
45 linetrace
= traceback
.format_list(trace
)
46 texttrace
= ''.join(linetrace
)
47 textexc
= ''.join(traceback
.format_exception_only(errtype
, value
))
49 # debug log information
51 outf
, logname
= Wammu
.ErrorLog
.SaveLog()
53 print 'Created debug log copy in %s for error reporting.' % logname
54 logtext
= '\n%s\n' % _('Debug log was saved for phone communication, if this error appeared during communicating with phone, you are strongly encouraged to include it in bugreport. Debug log is saved in file %s.') % logname
57 # detection of same errors
58 tracehash
= md5('%s,%s' % (textexc
, texttrace
)).hexdigest()
59 if tracehash
in ERROR_HISTORY
:
60 print 'Same error already detected, not showing dialog!'
62 print 'Exception: %s' % textexc
64 ERROR_HISTORY
.append(tracehash
)
66 # traceback id (md5 sum of last topmost traceback item inside Wammu - file(function):code)
68 for trace_line
in trace
:
69 if trace_line
[0].rfind('Wammu') > -1:
70 lasttrace
= trace_line
71 traceidtext
= '%s(%s):%s' % (
72 lasttrace
[0][lasttrace
[0].rfind('Wammu'):],
75 traceid
= md5(traceidtext
).hexdigest()
76 tracetext
= '\n%s\n' % (
77 _('Before submiting please try searching for simmilar bugs on %s')
78 % ('http://bugs.cihar.com/view_all_set.php?f=3&type=1&search=%s\n'
85 if errtype
== UnicodeEncodeError or errtype
== UnicodeDecodeError:
86 unicodewarning
= ('\n%s\n' %
87 _('Unicode encoding error appeared, see question 1 in FAQ, how to solve this.'))
97 ------------------ Traceback ID -------------------
99 -------------------- Traceback --------------------
100 %s-------------------- Exception --------------------
101 %s---------------------------------------------------
103 _('Unhandled exception appeared.'),
104 _('If you want to help improving this program, please submit following infomation and description how did it happen to %s. Please report in english, otherwise you will be most likely told to translate you report to english later.') % 'http://bugs.wammu.eu/',
108 Wammu
.ErrorLog
.GetSystemInfo(),
113 # Include exception info in crash file
115 outf
.write(text
.encode('utf-8'))
120 Wammu
.ErrorMessage
.ErrorMessage(HANDLER_PARENT
,
121 _('Unhandled exception appeared. If you want to help improving this program, please report this together with description how this situation has happened. Please report in english, otherwise you will be most likely told to translate you report to english later.'),
122 _('Unhandled exception'),
123 traceid
= traceid
, autolog
= logname
,
124 exception
= _('Traceback:\n%(traceback)s\nException: %(exception)s') % {
125 'traceback': StrConv(texttrace
),
126 'exception' : StrConv(textexc
) }).ShowModal()