[Sugar-devel] [Sugar] Show a clean error in log if not libraries needed to do tts - SL #3345

Sascha Silbe silbe at activitycentral.com
Mon Apr 23 18:07:56 EDT 2012


Excerpts from godiard's message of 2012-03-09 19:44:08 +0100:

> From: Gonzalo Odiard <godiard at gmail.com>

How about this for a patch summary and description:

Handle missing gst-plugins-espeak gracefully (fixes SL#3345)

The text-to-speech support in Sugar (jarabe.model.speech) depends on
gst-plugins-espeak [1]. While Sugar continues to work properly in the
absence of gst-plugins-espeak, loading the corresponding components
(keyboard shortcut handler and Frame device icon) currently fails hard
and produces a traceback in the log. However TTS support is entirely
optional and the traceback suggests an unhandled system failure rather
than optional support not being available. Fix this by catching the
exception when accessing the SpeechManager and logging a warning
instead.

[1] https://wiki.sugarlabs.org/go/Activity_Team/gst-plugins-espeak


[extensions/deviceicon/speech.py]
[...]
> +tts_available = True
> +try:
> +    from jarabe.model import speech
> +except:
> +    logging.error('Text to speech no avalable: error loading dependencies')
> +    tts_available = False

We should not use unqualified except: (i.e. catching _all_ exceptions)
except in very rare circumstances. You expect a specific set of
exceptions, so catch only those. Catching everything else only hides
problems. It may be necessary to catch the low-level exception in
jarabe.model.speech.SpeechManager and raise a different one (maybe
even a custom one) instead. We don't want implementation details of
jarabe.model.speech leaking into other components. That's the whole
purpose of a model.

Just importing the module should not raise an exception. Only
accessing the singleton instance provided by the module (via
get_speech_manager()) should. A quick inspection of
jarabe.model.speech suggests it already works (resp. fails) that way,
so I'm not sure whether you've actually tested your patch.

Since TTS support is optional, we should only log a warning, not an
error. Nothing broke, it's just that we could offer an additional
feature if gst-plugins-espeak were available.


Thanks for working on this! It may seem superfluous to some as
everything works "fine" even without the patch, but having Tracebacks
in the log despite the system operating as it should makes debugging
and error feedback harder. In the long run I'd even like to inform the
user when an unexpected error occurs, because that means that the
system may break in subtle ways and the user may loose data if they
continue working. Any unexpected error (i.e. uncaught exception) is an
admission that we messed up badly and don't know what will happen
next.

Sascha

-- 
http://sascha.silbe.org/
http://www.infra-silbe.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20120424/bc2e117d/attachment.pgp>


More information about the Sugar-devel mailing list