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 - 2008 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
29 import Wammu
.ErrorMessage
30 from Wammu
.Locales
import StrConv
32 # set later in Wammu.App to have correct parent here
37 def Handler(errtype
, value
, tback
):
38 """User friendly error handling """
40 # prepare traceback text
41 trace
= traceback
.extract_tb(tback
)
42 linetrace
= traceback
.format_list(trace
)
43 texttrace
= ''.join(linetrace
)
44 textexc
= ''.join(traceback
.format_exception_only(errtype
, value
))
46 # debug log information
48 outf
, logname
= Wammu
.ErrorLog
.SaveLog()
50 print 'Created debug log copy in %s for error reporting.' % logname
51 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
54 # detection of same errors
55 tracehash
= md5
.new('%s,%s' % (textexc
, texttrace
)).hexdigest()
56 if tracehash
in ERROR_HISTORY
:
57 print 'Same error already detected, not showing dialog!'
59 print 'Exception: %s' % textexc
61 ERROR_HISTORY
.append(tracehash
)
63 # traceback id (md5 sum of last topmost traceback item inside Wammu - file(function):code)
65 for trace_line
in trace
:
66 if trace_line
[0].rfind('Wammu') > -1:
67 lasttrace
= trace_line
68 traceidtext
= '%s(%s):%s' % (
69 lasttrace
[0][lasttrace
[0].rfind('Wammu'):],
72 traceid
= md5
.new(traceidtext
).hexdigest()
73 tracetext
= '\n%s\n' % (
74 _('Before submiting please try searching for simmilar bugs on %s')
75 % ('http://bugs.cihar.com/view_all_set.php?f=3&type=1&search=%s\n'
82 if errtype
== UnicodeEncodeError or errtype
== UnicodeDecodeError:
83 unicodewarning
= ('\n%s\n' %
84 _('Unicode encoding error appeared, see question 1 in FAQ, how to solve this.'))
94 ------------------ Traceback ID -------------------
96 -------------------- Traceback --------------------
97 %s-------------------- Exception --------------------
98 %s---------------------------------------------------
100 _('Unhandled exception appeared.'),
101 _('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/',
105 Wammu
.ErrorLog
.GetSystemInfo(),
110 # Include exception info in crash file
112 outf
.write(text
.encode('utf-8'))
117 Wammu
.ErrorMessage
.ErrorMessage(HANDLER_PARENT
,
118 _('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.'),
119 _('Unhandled exception'),
120 traceid
= traceid
, autolog
= logname
,
121 exception
= _('Traceback:\n%(traceback)s\nException: %(exception)s') % {
122 'traceback': StrConv(texttrace
),
123 'exception' : StrConv(textexc
) }).ShowModal()