<div class="gmail_quote">On 14 October 2010 08:50, Mukul Gupta <span dir="ltr"><<a href="mailto:mukul@seeta.in">mukul@seeta.in</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote">Team,<br>
<br></div><div class="gmail_quote">Wish to have your feedback on the
design aspect of the ticket 2063 (Sugar should bring up an alert when an
unhandled Python exception occurs) - please find the git diff attached
below. This is an attempt to display an alert when an unhandled Python
exception occurs in the journal. Unfortunately, when the exception takes
place in journalactivity.py , I am neither unable to notice the Journal
Icon (it disappears), </div><div>
<div class="gmail_quote"><br>
<br>
diff --git a/journalactivity.py b/journalactivity.py<br>
index 44cc018..36a2e2e 100644<br>
--- a/journalactivity.py<br>
+++ b/journalactivity.py<br>
@@ -358,8 +358,20 @@ class JournalActivity(Window):<br>
self.show_main_view()<br>
self.search_grab_focus()<br>
<br>
+ def uncaught_exception_alert(self):<br>
+ alert = ErrorAlert(title="Operation could not be performed", msg="Please check the logviewer activity for details ")<br></div></div></blockquote><div><br>We can improve the helpfulness of this message. For example, we can tell people which file to open in the log. I would like to give some recommended steps to help get problems fixed, but I haven't included it here. Also, if they don't have the log viewer activity, then they may feel helpless:<br>
<br>def uncaught_exception_alert(self):<br> from glob import glob<br> from os import system<br><br> logger = ... # should be easy to find<br> recentlog = glob(<span class="s">"{0}</span><span class="si"></span><span class="s">*".format(</span><span class="o"></span>logger.filename))[-1]<br>
last_log_line = system("tail -n 1 {0}".format(recentlog))<br><br> alert = ErrorAlert(title=_("Sorry, something went wrong"),<br> msg = _("Please check the file {0} for details.\nThe last line of that file is:\n{1}").format(<br>
recentlog,<br> last_log_line))<br> ...<br></div><div> <br>I also don't like the function name uncaught_exception_alert. Functions should generally begin with verbs. Perhaps handle_uncaught_exception?<br>
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div> _journal = None<br>
<br>
+def _alert_excepthook(exc_type, exc_value, traceback):<br>
+ logging.exception('Unhandled Python exception: %s', repr((exc_type, exc_value, traceback)))<br>
+ _journal.uncaught_exception_alert() <br>
+<br>
+sys.excepthook = _alert_excepthook<br> </div></div></blockquote><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div> </div></div></blockquote>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div class="gmail_quote">+<br>
def get_journal():<br>
global _journal<br>
if _journal is None:<br>
-- <br>
1.7.0.4</div><div class="gmail_quote"><br></div></div><div class="gmail_quote"><br>
I wish to request you to please review the code and suggest desired changes, if any.<br>
<br>
Moreover, I have two important questions regarding the bug.<br>
<br>
1. To catch all unhandled python exceptions in sugar, where exactly
should we be looking forward to be the venue for adding the
functionality?<div><br>
Adding it in journalactivity.py doesn't seem to serve all purposes.
It has to be added somewhere which is being used all the time.<br>
<br></div>
2. Wish if you could recommend on the GUI feature that could be used for displaying the alert message to the user.<br>
<br>Looking forward to for your valuable suggestions,</div></blockquote></div>