[Sugar-devel] SL Bug #2063

Tim McNamara paperless at timmcnamara.co.nz
Wed Oct 13 16:41:58 EDT 2010


On 14 October 2010 08:50, Mukul Gupta <mukul at seeta.in> wrote:

> Team,
>
> 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),
>
>
> diff --git a/journalactivity.py b/journalactivity.py
> index 44cc018..36a2e2e 100644
> --- a/journalactivity.py
> +++ b/journalactivity.py
> @@ -358,8 +358,20 @@ class JournalActivity(Window):
>          self.show_main_view()
>          self.search_grab_focus()
>
> +    def uncaught_exception_alert(self):
> +        alert = ErrorAlert(title="Operation could not be performed",
> msg="Please check the logviewer activity for details ")
>

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:

def uncaught_exception_alert(self):
    from glob import glob
    from os import system

    logger = ... # should be easy to find
    recentlog = glob("{0}*".format(logger.filename))[-1]
    last_log_line = system("tail -n 1 {0}".format(recentlog))

    alert = ErrorAlert(title=_("Sorry, something went wrong"),
        msg = _("Please check the file {0} for details.\nThe last line of
that file is:\n{1}").format(
            recentlog,
            last_log_line))
    ...

I also don't like the function name uncaught_exception_alert. Functions
should generally begin with verbs. Perhaps handle_uncaught_exception?

 _journal = None
>
> +def _alert_excepthook(exc_type, exc_value, traceback):
> +    logging.exception('Unhandled Python exception: %s', repr((exc_type,
> exc_value, traceback)))
> +    _journal.uncaught_exception_alert()
> +
> +sys.excepthook = _alert_excepthook
>
>

>
+
>  def get_journal():
>      global _journal
>      if _journal is None:
> --
> 1.7.0.4
>
>
> I wish to request you to please review the code and suggest desired
> changes, if any.
>
> Moreover, I have two important questions regarding the bug.
>
> 1. To catch all unhandled python exceptions in sugar, where exactly should
> we be looking forward to be the venue for adding the functionality?
>
>     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.
>
> 2. Wish if you could recommend on the GUI feature that could be used for
> displaying the alert message to the user.
>
> Looking forward to for your valuable suggestions,
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20101014/d8b0b1e9/attachment.html>


More information about the Sugar-devel mailing list