Skip to content

Commit

Permalink
Fix some problems with UnknownWordsError handling in SphinxEngine
Browse files Browse the repository at this point in the history
- Add two missing except blocks in SphinxEngine methods.
- Use 'e' instead of the deprecated 'e.message' which doesn't
  exist in Python 3.5.
  • Loading branch information
drmfinlay committed Nov 12, 2018
1 parent 6d78fdd commit 533e19c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions dragonfly/engines/backend_sphinx/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def speech_start():
)
except UnknownWordError as e:
# Log the error about unknown words.
self._log.error(e.message)
self._log.error(e)

# Initialise a TrainingDataWriter instance if specified.
if self.config.TRAINING_DATA_DIR:
Expand Down Expand Up @@ -447,7 +447,7 @@ def set_keyphrase(self, keyphrase, threshold, func):
self._validate_words(keyphrase.split(), "keyphrase")
except UnknownWordError as e:
# Log an error and return early.
self._log.error(e.message)
self._log.error(e)
return

# Add parameters to the relevant dictionaries.
Expand Down Expand Up @@ -498,7 +498,7 @@ def _load_grammar(self, grammar):
except UnknownWordError as e:
# Unknown words should be logged as plain error messages, not
# exception stack traces.
self._log.error(e.message)
self._log.error(e)
except Exception as e:
self._log.exception("Failed to load grammar %s: %s."
% (grammar, e))
Expand Down Expand Up @@ -540,6 +540,8 @@ def activate_rule(self, rule, grammar):
wrapper.dictation_grammar.enable_rule(rule.name)
self.unset_search(wrapper.search_name)
self.set_grammar(wrapper)
except UnknownWordError as e:
self._log.error(e)
except Exception as e:
self._log.exception("Failed to activate grammar %s: %s."
% (grammar, e))
Expand All @@ -553,6 +555,8 @@ def deactivate_rule(self, rule, grammar):
wrapper.dictation_grammar.disable_rule(rule.name)
self.unset_search(wrapper.search_name)
self.set_grammar(wrapper)
except UnknownWordError as e:
self._log.error(e)
except Exception as e:
self._log.exception("Failed to activate grammar %s: %s."
% (grammar, e))
Expand Down

0 comments on commit 533e19c

Please sign in to comment.