[Dextrose] [PATCH sugar-toolkit] More robust handling of unhandled exceptions

Anish Mangal anishmangal2002 at gmail.com
Wed Feb 2 10:51:50 EST 2011


committed to dx/mainline

http://git.sugarlabs.org/dextrose/mainline/commit/c6d7845fce52a9b0c345aea103e2d3672426dd61

On Mon, Jan 24, 2011 at 07:57, Aleksey Lim <alsroot at member.fsf.org> wrote:
> ---
>  src/sugar/feedback.py |   24 +++++++++++++++---------
>  1 files changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/src/sugar/feedback.py b/src/sugar/feedback.py
> index 56dacab..770b7a7 100644
> --- a/src/sugar/feedback.py
> +++ b/src/sugar/feedback.py
> @@ -79,6 +79,11 @@ def _send(activity_id, log_path):
>             log_path if need_log else '')
>
>
> +def _format_exception(exctype, value, tb):
> +    import traceback
> +    return ''.join(traceback.format_exception(exctype, value, tb))
> +
> +
>  def _excepthook(exctype, value, tb):
>     global _log_formatter
>
> @@ -89,15 +94,16 @@ def _excepthook(exctype, value, tb):
>             from IPython.ultraTB import AutoFormattedTB
>             formatter = AutoFormattedTB(mode='Verbose', color_scheme='NoColor')
>             _log_formatter = formatter.text
> -        except ImportError:
> -            import traceback
> -            _log_formatter = \
> -                    lambda * args: ''.join(traceback.format_exception(*args))
> -
> -    message = _log_formatter(exctype, value, tb)
> -    logging.error(message)
> -
> -    trigger('unhandled_exception', need_log=True)
> +        except BaseException:
> +            _log_formatter = _format_exception
> +
> +    try:
> +        message = _log_formatter(exctype, value, tb)
> +        logging.error(message)
> +        trigger('unhandled_exception', need_log=True)
> +    except BaseException, error:
> +        print >>sys.stderr, 'Unhandled %r while processing: %r %r' % \
> +                (error, exctype, value)
>
>
>  sys.excepthook = _excepthook
> --
> 1.7.3.4
>
> _______________________________________________
> Dextrose mailing list
> Dextrose at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/dextrose
>



-- 
Anish


More information about the Dextrose mailing list